且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何授予PHP对目录的写访问权限?

更新时间:2022-04-28 22:26:31

一种简单的方法是让PHP首先创建目录本身.

An easy way is to let PHP create the directory itself in the first place.

<?php
 $dir = 'myDir';

 // create new directory with 744 permissions if it does not exist yet
 // owner will be the user/group the PHP script is run under
 if ( !file_exists($dir) ) {
     mkdir ($dir, 0744);
 }

 file_put_contents ($dir.'/test.txt', 'Hello File');

这为您节省了权限的麻烦.

This saves you the hassle with permissions.