Linux file Upload, the way to add Apache permissions to files or directories _linux

Source: Internet
Author: User
Tags file upload php file upload

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.