Permission denied for subfolder
P粉334721359
P粉334721359 2024-03-27 15:08:16
0
1
310

Context

  • PHP 5.6
  • IIS
  • Windows 11

question

I'm trying to write a file in a specific folder but it's giving me permission returned . So I verified the permissions and everything seemed fine. Since this is in a development environment, I decided to change the permissions on the "root" folder that writes all files to "Everyone can do anything." I tried replacing all permissions below. I'm trying to remove inherited permissions. Nothing can be done.

Then I try to write a file in the "root" folder. It worked. On subfolders it worked. on sub-subfolders. efficient. There is a point in the subfolder chain where it doesn't work, but before the actual subfolder.

This is the path hierarchy at the time of the crash.

$f = new \wee\common\IO\File();
$f->write("DRIVE:/BASE_PATH/files/-/00.jpg", "hello"); // WORKS
$f->write("DRIVE:/BASE_PATH/files/-/mod/00.jpg", "hello"); // WORKS
$f->write("DRIVE:/BASE_PATH/files/-/mod/com.ci.company/00.jpg", "hello"); // WORKS
$pathLength = strlen("DRIVE:/BASE_PATH/files/-/mod/com.ci.company/site/00.jpg"); // Real path length is 85
$f->write("DRIVE:/BASE_PATH/files/-/mod/com.ci.company/site/00.jpg", "hello"); // FAILS
$f->write("DRIVE:/BASE_PATH/files/-/mod/com.ci.company/site/WorkersManager/00.jpg", "hello");
$f->write("DRIVE:/BASE_PATH/files/-/mod/com.ci.company/site/WorkersManager/workers/00.jpg", "hello");

Class \wee\common\IO\File was created by me, but can be used in many other places.

The exact error message I received was:

fopen(DRIVE:/BASE_PATH/files/-/mod/com.ci.company/site/00.jpg): Unable to open stream: Permission denied

100% clear: the "root" folder is DRIVE:/BASE_PATH/files/

Edit#1

Here is the implementation of the write method of the File class.

public function write($fileName, $data, $lock = false) {
    $this->_write($fileName, $data, $lock);
}

private function _write($fileName, $data, $lock = false, $openMode = 'w') {
    if ($data === null)
        $data = "";
    
    $fh = fopen($fileName, $openMode) or die("can't open file"); // FAILS HERE
    if ($lock) {
        flock($fh, LOCK_EX);
    }
    fwrite($fh, (is_array($data) ? join("\n", $data) : $data));
    if ($lock) {
        fflush($fh);
        flock($fh, LOCK_UN);
    }
    fclose($fh);
}

P粉334721359
P粉334721359

reply all(1)
P粉819533564

This issue comes from PHP 5.6.26. This issue is fixed with PHP 5.6.40.

I reset to original permissions and everything is fine!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!