好的,测试 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: ".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";
输出:
Original Permissions: 1407<br />
Test 1 Permissions: 0775<br />
Test 2 Permissions: 0775<br />
为什么这不起作用?
// $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";
测试 3 有效,但仍不是主要示例。啊!!!
编辑#2:
我想我发现了问题,当我回显变量的类型时,它是一个字符串。
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
为什么是这样?