php - move_uploaded_file函数问题


I am facing issue with the move_uploaded_file() php function below is my script.
Its saying permission denied . The directory is not writable . But I checked the permissions , its read-write-execute. Not Sure what's the issue , How do I make sure the permission is R-W-X. ?

<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
$target = "BharatTest/";
$photoName = basename( $_FILES['image']['name']);
$target = $target . basename( $_FILES['image']['name']) ;

ini_set('display_errors', 1);
echo '<pre>Debug: tmp file:', htmlspecialchars($_FILES['image']['tmp_name']), "</pre>
";
echo '<pre>Debug: target directory: ', htmlspecialchars("BharatTest/"), "</pre>
";
echo '<pre>Debug: real target: ', htmlspecialchars(realpath("BharatTest/")), "</pre>
";
echo '<pre>Debug: source readable: ', is_readable($_FILES['image']['tmp_name']), "          
</pre>
";
echo '<pre>Debug: target is_dir: ', is_dir("BharatTest/") ? 'yes':'no', "</pre>
";
echo '<pre>Debug: target writable: ', is_writeable("BharatTest/") ? 'yes':'no', "    
</pre>
";

if(move_uploaded_file($_FILES['image']['tmp_name'], $target))
{
   echo "YES";
}
else 
{
    echo "NO";
}
?> 

You need to ensure the webserver user has write permissions. Depending on the setup this often requires 775 or even 777 permissions on the folder.

Just because the directory is writable to you (when you log in), does not mean that it is writable to PHP / Apache / whatever web server you have. Depending on your server configuration, PHP likely runs with an entirely different set of permission. You can either lookup the permissions for your web server or set the directory to 777 and then backoff from there to determine the correct permissions for the directory.