Centos php production environment encountered permission problems in file generation

the server system is centos
with pagoda panel
php version is 7.2

the specific code is as follows

//"./attachment/qrcode/user" 
$path="./attachment/qrcode/user";
if(!is_dir($path)){
    mkdir($path,"0777",1);
}
//1.txt

1. The error is prompted first after running

mkdir(): Permission denied

check the directory where the files are generated, because attachment originally has 777 permissions, and the qrcode directory is generated, but the following user directory is not generated

2. After giving permission to qrcode directory 777, run it again with an error

.
fopen(./attachment/qrcode/user/1.txt): failed to open stream: Permission denied

check the directory where the generated files are generated. If the user directory is generated, you will continue to set the 777 permissions to the user directory without permission.
run it again, and the 1.txt file will be generated successfully

.

the code has set "mkdir ($path," 0777 ", 1);"
should be generated recursively according to the path and set 777permissions.
what is the reason for this?

Jul.08,2022

Note: the $mode parameter is int

.
mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] ) : bool

modify to:

mkdir($path, 0777, 1);

Thank you for the invitation. After reading the underlying source code, the second parameter is required to be int. If you leave it empty, the permission is 0777 by default.


mkdir ($path, 0777, true);


'0777' and 0777
are different

0777 is octal, so converting to a string should be '511' , not ' 0777'


mkdir($path, 0777, 1);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e62dc5-459ff.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e62dc5-459ff.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?