In the lamp environment, testing a simple php file upload function, found in the/var/log/apache2/error.log the following PHP warning:
1. [Tue 09:40:27] [ERROR] [client 127.0.0.1] PHP warning:move_uploaded_file (/home/leotody/32883679.jpeg): FAI Led to open Stream:permission denied in/var/www/upload_file.php in line, referer:http://localhost/info.html
2. [Tue 09:40:27] [ERROR] [client 127.0.0.1] PHP warning:move_uploaded_file (): Unable to move '/tmp/phps05ssu ' To '/home/leotody/32883679.jpeg ' in/var/www/upload_file.php in line, referer:http://localhost/info.html
Prompt does not have access rights, the file uploads the code as follows:
if (file_exists ("upload/". $_files["File" ["Name"])
{
echo $_files["file"] ["name"]. "already exists.";
}
else
{
if (move_uploaded_file ($_files["file"] ["Tmp_name"], "upload/". $_files["File" ["Name"]))
{
echo "Stored in:". Upload/". $_files["File" ["name"];
}
else
{
echo ' move error! ';
}
}
The "Move error!" appears in the page, stating that the Move_uploaded_file () function failed to execute.
By looking for data, found that the internet is said to be the cause of selinux, check the system did not start SELinux, view the upload directory default permissions ls-ld upload, the result is 755:
1. drwxr-xr-x 2 root root 4096 2012-01-31 10:59 upload
Change the upload directory permissions to 777,sudo chmod 777 upload, and then test the upload function successfully. However, this method of modifying permissions is not secure.
It can be changed to upload directory owner for Www-data (that is, Apache), sudo chown-r www-data:www-data upload, and then test the upload function successfully.
1. Drwxr-xr-x 2 www-data www-data 4096 2012-01-31 10:59 upload
The above Linux file upload, to the file or directory to add Apache permissions is a small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.