I need to make every file with UNIQUE name so i guess stamping date and time (including seconds) would do the trick 😉

Problem is dont know how heres my code until now:

$fecha = date('Y/n/j h:i:s');
$uploaddir = '../archivos/';
$uploadfile = $uploaddir . basename($FILES['imagen']['name']);
move_uploaded_file($
FILES['imagen']['tmp_name'], $uploadfile);

This works only to upload the file and it works, the name of the image variable on the post form is 'IMAGEN'

If you could help me to rename the file with the date and time (ie. 20060101121201.ext) and keeping the extension would be fine !

Example filename is 1st january 2006 12 hours 12 minutes 01 seconds (uploading time).

    Try something like:

    <?php
      $fecha       = date('Y/n/j h:i:s');
      $uploaddir = '../archivos/';
      $uploadfile = $uploaddir . basename($_FILES['imagen']['name']);
      move_uploaded_file($_FILES['imagen']['tmp_name'], $uploadfile);
      # Our date...
      $Date2       = date('YmdHis');
      $DotPos     = strpos($File, '.');
      $Extension = substr($File, $DotPos, strlen($File) - $DotPos);
      rename($uploadfile, $uploaddir . $Date2 . $Extension);
    ?>
    

    Not shure if that exact code will work but something along thse lines should 🙂

    Cheers,

    Ryan Jones

      RyanJones wrote:

      Try something like:

      <?php
        $fecha       = date('Y/n/j h:i:s');
        $uploaddir = '../archivos/';
        $uploadfile = $uploaddir . basename($_FILES['imagen']['name']);
        move_uploaded_file($_FILES['imagen']['tmp_name'], $uploadfile);
        # Our date...
        $Date2       = date('YmdHis');
        $DotPos     = strpos($File, '.');
        $Extension = substr($File, $DotPos, strlen($File) - $DotPos);
        rename($uploadfile, $uploaddir . $Date2 . $Extension);
      ?>
      

      Not shure if that exact code will work but something along thse lines should 🙂

      Cheers,

      Ryan Jones

      Thanx, it does work EXCEPT the extension is removed 🙁 but the file is renamed to the date and hour 😉

      any fix to preserve the extension? thanks 🙂

        newbieiguess wrote:

        Thanx, it does work EXCEPT the extension is removed 🙁 but the file is renamed to the date and hour 😉

        any fix to preserve the extension? thanks 🙂

        Sorry... my bad 🙁

        <?php
          $fecha       = date('Y/n/j h:i:s');
          $uploaddir = '../archivos/';
          $uploadfile = $uploaddir . basename($_FILES['imagen']['name']);
          move_uploaded_file($_FILES['imagen']['tmp_name'], $uploadfile);
          # Our date...
          $Date2       = date('YmdHis');
          $DotPos     = strpos($uploadfile, '.');
          $Extension = substr($uploadfile, $DotPos, strlen($uploadfile) - $DotPos);
          rename($uploadfile, $uploaddir . $Date2 . $Extension);
        ?>
        [code=php]
        
        Should fix it :)
        
        Cheers,
        
        Ryan Jones
          RyanJones wrote:

          Should fix it 🙂

          Cheers,

          Ryan Jones

          Actually, i did try that 😉 (changin $file) but this errors shows now:

          Warning: rename(../archivos/image.jpg,../archivos/20060121185320../archivos/image.jpg): No such file or directory in /home/account/public_html/uploads/upload.php on line 24

          Maybe something to do with the directories?

          the script is in

          /uploads/upload.php

          the files are going to:

          /archivos

          Thanx 🙂

          P.S. The file are being upload OK but now no renaming is done.

            change the upload-dir var to /archivos/ instead of ../archivos/ and this shows:

            Warning: move_uploaded_file(): SAFE MODE Restriction in effect. The script whose uid is 32032 is not allowed to access / owned by uid 0 in /home/account/public_html/uploads/upload.php on line 16

            Warning: rename(): SAFE MODE Restriction in effect. The script whose uid is 32032 is not allowed to access / owned by uid 0 in /home/account/public_html/uploads/upload.php on line 24

            and now no renaming or uploading is done. :S

              Thanx now it works !!

              teach a man to fish uh?

              I shall now start the paperwork to make you a GOD!! 😉

              see ya thanx!!

                Oh yes... the dots...

                Try:

                <?php
                $fecha         = date('Y/n/j h:i:s');
                $uploaddir   = '../archivos/';
                $uploadfile  = $uploaddir . basename($_FILES['imagen']['name']);
                move_uploaded_file($_FILES['imagen']['tmp_name'], $uploadfile);
                # Our date...
                $Date2       = date('YmdHis');
                $Parts        = explode('.', $uploadfile);
                $Extension = '.' . $Parts[(count($Parts) - 1];
                rename($uploadfile, $uploaddir . $Date2 . $Extension);
                ?>
                

                That SHOULD work I think 🙂

                Not thinking strait, 3AM and I have no coffee left 🙁

                Cheers,

                Ryan Jones

                  Write a Reply...