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/
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); }
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!