move_upoaded_file permissions problem - Does something need configured on server?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bizt

    move_upoaded_file permissions problem - Does something need configured on server?

    Hi,

    I am trying to carry out an upload and save file in directory operation
    using move_uploaded_f ile(). However, when I run the script it give me
    the following error:

    Warning: move_uploaded_f ile(photos/sonyericsson_t6 10.jpg): failed to
    open stream: Permission denied in
    /home/martyn69/public_html/photos/add_photo.php on line 41

    Warning: move_uploaded_f ile(): Unable to move '/tmp/phphPIdIj' to
    'photos/sonyericsson_t6 10.jpg' in
    /home/martyn69/public_html/photos/add_photo.php on line 41


    I have ensured that the permissions for the folder are set to 777.
    Also, I know that the file has been successfully uploaded as I have got
    the processing script to display the filename, size, type etc. The
    problem occurs at the move_uploaded_f ile() part. Does something need
    configured on the server for this to work?

    Cheers

    Martyn Bissett

  • Erwin Moller

    #2
    Re: move_upoaded_fi le permissions problem - Does something need configured on server?

    bizt wrote:
    Hi,
    >
    I am trying to carry out an upload and save file in directory operation
    using move_uploaded_f ile(). However, when I run the script it give me
    the following error:
    >
    Warning: move_uploaded_f ile(photos/sonyericsson_t6 10.jpg): failed to
    open stream: Permission denied in
    /home/martyn69/public_html/photos/add_photo.php on line 41
    >
    Warning: move_uploaded_f ile(): Unable to move '/tmp/phphPIdIj' to
    'photos/sonyericsson_t6 10.jpg' in
    /home/martyn69/public_html/photos/add_photo.php on line 41
    >
    >
    I have ensured that the permissions for the folder are set to 777.
    Also, I know that the file has been successfully uploaded as I have got
    the processing script to display the filename, size, type etc. The
    problem occurs at the move_uploaded_f ile() part. Does something need
    configured on the server for this to work?
    >
    Cheers
    >
    Martyn Bissett
    Hi Martyn,

    2 folders are of import in this situation:
    1) The folder where PHP stores the temp-file containing the uploaded file.
    Often this is the temp directory.
    2) The folder where you want to move the file to.

    Maybe you have an exotic situation where PHP can store the file in the
    tempdir, but has NO readpermissions on it. (Write yes, read no).

    To check if this is the case:
    1) check which directory is used to by PHP to store tempfiles,
    2) check its filepermissions for user PHP (apache/nobody/www-data, whatever
    that is in your case).

    Hope that helps.
    Regards,
    Erwin Moller

    Comment

    • bizt

      #3
      Re: move_upoaded_fi le permissions problem - Does something need configured on server?

      To check if this is the case:
      1) check which directory is used to by PHP to store tempfiles,
      2) check its filepermissions for user PHP (apache/nobody/www-data, whatever
      that is in your case).
      Thanks for that

      Now, I purchase my webspace from a hosting company. Would I, in most
      cases, have access to the temp dir and would I be able to change the
      file permissions? I contacted my hosting company and they made some
      changes that allowed it to work but they didnt give much info into what
      was carried out.

      Cheers

      Burnsy

      Comment

      • Erwin Moller

        #4
        Re: move_upoaded_fi le permissions problem - Does something need configured on server?

        bizt wrote:
        >To check if this is the case:
        >1) check which directory is used to by PHP to store tempfiles,
        >2) check its filepermissions for user PHP (apache/nobody/www-data,
        >whatever that is in your case).
        >
        Thanks for that
        >
        Now, I purchase my webspace from a hosting company. Would I, in most
        cases, have access to the temp dir and would I be able to change the
        file permissions?
        Yes, under most setups you have both write and read permissions on such a
        temp dir.
        Of course, the filepermissions of the files you want to access (via
        move_uploaded)f ile()) IN the tempdir is what really matters.

        Maybe your hostingcompany made PHP store files as the PHP-user with no
        readrights, which sounds very strange to me.

        You can check this yourself by using php_info(), and see what you can find
        out about the tempdirectory. If you have shellaccess you can see the
        directorypermis sions yourself.

        I contacted my hosting company and they made some
        changes that allowed it to work but they didnt give much info into what
        was carried out.
        Good it works now. Bad they didn't give you a short description on what they
        changed. That way it is hard to learn what went wrong.
        >
        Cheers
        >
        Burnsy

        Regards,
        Erwin Moller

        Comment

        Working...