I'm running into problems with a simple file upload. The error message indicates that it is a permission problem, but all the paths involved in this are set to 777 permissions.

Boiled down to its essence the code is this:

<?php

if ($HTTP_POST_VARS['submit']) {
    echo '<pre>';
    print_r($_FILES);
    echo '</pre>';

    $result = move_uploaded_file($_FILES['file']['tmp_name'], "images/coupons/" . $_FILES['file']['name']);
    if ($result)    {
        print '<br>File has been successfully uploaded! MoveResult was:' . $result . '<br>';
        }    else {
        print 'File FAILED to upload! MoveResult was:' . $result . '<br>';
    }
}
?>

<html>
<head></head>
<body>
<form action="<?=$PHP_SELF?>" method="post" enctype="multipart/form-data">
<br><br>
Choose a file to upload:<br>
<input type="file" name="file"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

Here is the output from running the code:

    Array
    (
        [file] => Array
            (
                [name] => 4aa.jpg
                [type] => image/jpeg
                [tmp_name] => /tmp/phpaSNfJ6
                [error] => 0
                [size] => 84185
            )

)

Warning: move_uploaded_file(images/coupons/4aa.jpg): failed to open stream:
      Permission denied in /home/w4ralphy/public_html/zzz2.php on line 8

Warning: move_uploaded_file(): 
      Unable to move '/tmp/phpaSNfJ6' to 'images/coupons/4aa.jpg' 
      in /home/w4ralphy/public_html/zzz2.php on line 8

File FAILED to upload! MoveResult was:

I've also tried to see if the first step of the process - uploading the file to the tmp directory - is working as it should by adding an is_uploaded_file() check and commenting out the move_uploaded_file() code:

    if (is_uploaded_file ($_FILES['file']['tmp_name'])) {
        echo "File moved to tmp directory";}

Although is_uploaded_file() indicates that the first step succeded, I haven't been able to find any evidence of the temp file on the server.

    SOMETHING isn't set to 777...probably the directory where PHP does its initial upload. Check phpinfo() to see what this directory is, and check the permissions.

      OK. I finally got it. The problem was with the File Manager component of cPanel. Here's what was happening.

      If you click on a directory in File Manager you will be presented with a set of choices like this:

      public_html:
            Delete this folder and all files under it
            Rename this folder
            Change Permissions
            Move this folder
            Copy this folder 
      

      If you select Change Permissions you will see a table like this:

         public_html
      
      Mode        User     Group     World 
      Read         X         X         X   
      Write        X         X         X   
      Execute      X         X         X   
      Permission   7         7         7
      
      |--------|
      | Change |
      |--------|

      Now to you and me that probably looks like your permissions are set to 777, but apparently that's not the case. It seems you have to click on the "Change" button for that setting to actually take effect at which point you'll get a message saying, "Set permissions on public_html -> 0777".

      I don't know what my permissions were prior to clicking the "Change" button, but they weren't 777.

        Write a Reply...