Hi, probably a really simple question, when I upload an image file and use move_uploaded_file I am having trouble defining the correct path to where I want the file to end up.

Basically on my development server (a Mac running Apache) I want it transferred to a directory within my web app directory, something like this:

./library/webserver/documents/mywebapp/imageupload/

But I am unsure if move_uploaded_file is expecting a relative or absolute path, and so far I have had little success with:

move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
" the path to imageupload ");

Any help would be appreciated.

Thanks,

D

    The function will accept whichever path you prefer. Can you post the error message generated?

    Also, just to verify, with the above path, you're telling PHP that the "library" directory is in the same directory as the script being executed. Is this what you intended?

      Hi Brad,

      Thanks for your reply.

      The error code returned is 0, which seems to mean the file is uploaded OK, the php file is in a directory admin/imageup.php and I am trying to place it in a directory image here admin/image/

      So I call:

      $result = move_uploaded_file($FILES["imageFile"]["tmp_name"],
      "./image/" . $
      FILES["file"]["name"]);

      Which is not working.. any further help greatly appreciated!

      The temp file is /var/tmp/phpDakWER

      D

        Hi Brad,

        Thanks for the reply.

        I am attempting to move the image file to folder image in my admin folder where the php file is:

        admin/imageUp.php

        admin/image/

        Using this code in imageUp.php:

        $result = move_uploaded_file( $FILES['imageFile']['tmp_name'],
        "./image/".$
        FILES['imageFile']['name']);

        The error returned is 0 which seems to suggest everything is OK.

        The temp file is:/var/tmp/phpo2SFxo for example so the process should be:

        /var/tmp/phpo2SFxo -> ./image/atest.jpg

        But it fails. Any advice would be welcome!

        Thanks,

        D

          Seems to have been a permissions problem! Now the upload is successful on my test server.

          Any ideas on what the lowest possible ownership and permissions combination there is to allow a move_uploaded_file on a Unix based test server? (I am running Apache on a Mac OSX machine).

          Ta D

            Druk wrote:

            Any ideas on what the lowest possible ownership and permissions combination there is to allow a move_uploaded_file on a Unix based test server?

            That depends on how the server is configured. On some servers, the scripts are executed under your username, so you could have a more strict permission setting of 744. Normally, however, the server executes scripts as the "nobody" account, meaning you have to give the directories you want the webserver to write to a permission of 766.

              Thanks Brad,

              By setting the Owner to www (Read&Write) and the Group level to nobody (Read) on the upload folder I seem to be able to upload the image file to the directory and display it on a web page so so far so good.

              Thanks again for your help.

              D

                Write a Reply...