Php permission for creating files on the server

Source: Internet
Author: User
PHPcode $ resfopen (usrlocalasgconfigsmeet. conf, a +); fclose ($ res); if meet. if the conf file does not exist, you can create it, but it cannot be created on the server. you can run the ls command to check that there is no write permission. Therefore, you have added the judgment & nbsp; PHPc php permission to create files on the server
PHP code
  $res = fopen('/usr/local/asg/configs/meet.conf','a+');fclose($res);

If the meet. conf file does not exist on the local machine, it can be created, but it cannot be created on the server. you can run the ls command to check that there is no writable permission. Therefore, you have added a judgment in the code.
PHP code
  if(!is_writable('/usr/local/asg/configs')) {    system('chmod 777 /usr/local/asg/configs');}$res = fopen('/usr/local/asg/configs/meet.conf','a+');fclose($res);

After running, it cannot be created again.
PHP code
  if(!is_writable('/usr/local/asg/configs')) {    system('chmod 777 /usr/local/asg/configs');}system('touch /usr/local/asg/configs/meet.conf');

Run it, but it still doesn't work. use putty to log on to the server, use the command line to enter the directory, and directly use touch to create the directory, why is the php file unsuccessful ???


------ Solution --------------------
I think you can use the php function chmod to complete this operation.

In addition, you must grant this directory permission to the php running account.
------ Solution --------------------
If (! Is_dir ('/usr/local/asg/configs ')){
Mkdir ('/usr/local/asg/configs ');
Chmod ('/usr/local/asg/configs', 0777 );
}
------ Solution --------------------
How can I use php to assign directories without permissions?

Just like if you do not have the permission to enter the State Council, then you cannot dress up unless you look for a relationship.

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.