Hello

I am making an "upload files page" and I found out that I can change the directory where I want to store these files with move_uploaded_file and changing the php.ini.

What if I want some files to go to different folders?

Is any other way to do it?

Thanks for any recomendation in advance

    move_uploaded_file($_FILES['pic']['tmp_name'], $upload_name);

    where $upload_name has the path where u want to save the uploaded file. i think i grasped ur problem correctly.

      Hi again

      It seems to work well but it doesn´t upload the file. I get the File succesfully uploaded but there´s no file. Probably I´m missing something basic here.

      This is what I´ve done
      <?php
      $uploadDir = 'c:\apache\htdocs\mysite\images';
      $uploadFile = $uploadDir . $FILES['userfile']['name'];
      print "<pre>";
      if (move_uploaded_file($
      FILES['userfile']['tmp_name'], $uploadFile))

      {
      print "File was successfully uploaded. ";
      print "Debugging info:\n";
      print_r($FILES);
      }
      else
      {
      print "Error! Debugging info:\n";
      print_r($
      FILES);
      }
      print "</pre>";
      ?>

        when u say 'I get the File succesfully uploaded but there´s no file.' i assume that u get no error message but when u try to access the uploaded file u get nothing. so i suggest u check if the form has enctype=multipart/form-data ... thats necessary for the file to be uploaded.
        the code u posted seems to be ok.

          I still have problems with my uploading form. I checked the " enctype=multipart/form-data" and it´s correct. What I think that is happening is that maybe the file remains with the temp_name and never changes.

          I read this at the phpmanual:
          "The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed. "

          and I get this message anytime I upload a file:

          File was successfully uploaded. Debugging info:
          Array
          (
          [userfile] => Array
          (
          [name] => 1.jpg
          [type] => image/jpeg
          [tmp_name] => C:\WINDOWS\php2DC.tmp
          [size] => 960
          )
          )

          So I don´t know if the tmp_name must change?

          Thanx

            ok i think i figured out ... maybe this is the prob...
            change
            $uploadDir = 'c:\apache\htdocs\mysite\images';
            to
            $uploadDir = 'c:\apache\htdocs\mysite\images\';
            or locate ur file as 'c:\apache\htdocs\mysite\imagesfilename';
            🙂 hopefully now ur prob wud be solved!

              I sometimes get surprised when a little change in the code like adding a \ will make it work.

              Probably I would never figure that out!
              Thank you very much for your help

                Write a Reply...