Php chmod动态设置权限值
好的,测试1和2可以正常工作,但是如果我从数组中强制转换值,它就不工作了Php chmod动态设置权限值,php,arrays,file-permissions,chmod,Php,Arrays,File Permissions,Chmod,好的,测试1和2可以正常工作,但是如果我从数组中强制转换值,它就不工作了 $file = '/test/file.xlsx'; echo "Original Permissions: ".substr(decoct(fileperms($file)),2)."<br />\n\r"; // test 1 $permission = 0775; chmod($file,$permission); clearstatcache(); echo "Test 1 Permissions:
$file = '/test/file.xlsx';
echo "Original Permissions: ".substr(decoct(fileperms($file)),2)."<br />\n\r";
// test 1
$permission = 0775;
chmod($file,$permission);
clearstatcache();
echo "Test 1 Permissions: ".substr(decoct(fileperms($file)),2)."<br />\n\r";
// test 2
define("PERMISSION", 0775);
chmod($file,PERMISSION);
clearstatcache();
echo "Test 2 Permissions: ".substr(decoct(fileperms($file)),2)."<br />\n\r";
为什么会这样 它可能不起作用,因为在执行
$excel\u file\u permission=(int)$ini\u数组['excel\u file\u info']['excel\u file\u permission']时转换为整数值代码>。整数和八进制值不一样…我认为是类型转换造成了这个问题。尝试更改:
$excel_file_permission = (int)$ini_array['excel_file_info']['excel_file_permission'];
到
$ini\u数组['excel\u文件\u信息]['excel\u文件\u权限]]的当前值是多少?请尝试输入像“0777”或“0644”这样的值或您想要的其他权限值。在ini中,我将该值更改为0666,当脚本执行时,我获得权限:1232如果我在ini中像这样用单引号括起该值:“0775”,我获得权限:000如果我在ini中像这样用双引号括起该值:“0775”,我获得权限:1407如果ini中的值没有引号,如:0775,我获得权限:1407
// $ini_array['excel_file_info']['excel_file_permission']
// is in a ini file with the value set to 0775
if(isset($ini_array['excel_file_info']['excel_file_permission'])) {
$excel_file_permission = $ini_array['excel_file_info']['excel_file_permission'];
define("EXCEL_FILE_PERMISSION", $excel_file_permission);
} else {
$excel_file_permission = 0777;
define("EXCEL_FILE_PERMISSION", $excel_file_permission);
}
echo "Permissions Before chmod: ".substr(decoct(fileperms($file)),2)."<br />\n\r";
chmod($file,EXCEL_FILE_PERMISSION);
clearstatcache();
echo "Permissions After chmod: ".substr(decoct(fileperms($file)),2)."<br />\n\r";;
chmod($file,0755);
clearstatcache();
echo "Permissions Hard Coded chmod: ".substr(decoct(fileperms($file)),2)."<br />\n\r";;
// Before I chmod
Permissions Before chmod: 0644<br />
// Using the DEFINED CONSTANT w/ set value to 0775
Permissions After chmod: 1363<br />
// Hard Coded 0755
Permissions Hard Coded chmod: 0755<br />
// test 3
$permission = array('perm' => 0775);
chmod($file,$permission['perm']);
clearstatcache();
echo "Test 3 Permissions: ".substr(decoct(fileperms($file)),2)."<br />\n\r";
echo "Defined Excel File Permission: ".EXCEL_FILE_PERMISSION."\n\r";
echo "Defined Type: ".gettype(EXCEL_FILE_PERMISSION)."\n\r";
Defined Excel File Permission: 0775
Defined Type: string
$excel_file_permission = (int)$ini_array['excel_file_info']['excel_file_permission'];
$excel_file_permission = intval($ini_array['excel_file_info']['excel_file_permission'], 8);