从管理面板上传文件时文件权限设置不正确
我从另一位开发人员那里继承了一些代码,并且正在尝试解决文件权限问题。本质上,当从自定义管理面板上传文件时,它们会被授予非常奇怪的 363 权限级别,而不是 755 或 644。我联系了主机,他们说文件和文件夹权限存在问题。我无法通过 FTP 手动更改文件权限。我已经处理好了。我想做的是在上传文件后更改文件权限。它显示成功,但是当我通过 FTP 检查文件时,它仍然是 363。是我的代码错误还是有更简单的方法来解决这个问题。任何帮助将不胜感激。遵循的代码:
function fileUpload($destination, $filename, $codeupname="case")
{
// set_time_limit(0);
// ini_set("post_max_size", "30M");
// ini_set("upload_max_filesize", "30M");
// ini_set("memory_limit", -1 );
if ($_FILES[$filename]['name'] !="")
{
$unique_id_query = strtoupper(substr(md5(uniqid(rand(), true)), 0 ,16));
$unique_add = $unique_id_query;
$unique_name = $destination.$codeupname.$unique_add;
//chmod($destnation,"777");
if($_FILES[$filename]["error"] > 0)
{
//echo $_FILES[$filename]["error"]." - error";
return -1; // file error
}
else
{
$uploadedfile = $_FILES[$filename]['tmp_name'];
$destination1 = $unique_name.$_FILES[$filename]['name'];
$path = "../".$destination1;
$result = move_uploaded_file($uploadedfile, $path);
if(!$result)
{
return -1;
}
else
{
echo $result;
//SET PROPER READ PERMISSIONS
$path2 = "/home/content/f/a/c/faccounting/html/".$destination1;
echo "PATH: ".$path2."<br />";
$result2 = chmod($path2, "0755");
echo "Result: ".$result2;
return $destination1; // returning image name and path
}
}
}
else
{
return -1; // no file persent
}
}
I'm inheriting some code here from another developer and I'm trying to solve a file permissions issue. Essentially when files are uploaded from the custom admin panel, they are given the wildly odd 363 permission level opposed to say a 755 or 644. I contacted the host and they said that there were issues with files and folder permissions. I was unable to manual change the file permissions through FTP. I got that taken care of. What I'm trying to do is change the file permissions after it is uploaded. It shows success but when I check the file through FTP, it's still 363. Is my code wrong or is there any easier way to fix this issue even. Any help would be appreciated. Code to follow:
function fileUpload($destination, $filename, $codeupname="case")
{
// set_time_limit(0);
// ini_set("post_max_size", "30M");
// ini_set("upload_max_filesize", "30M");
// ini_set("memory_limit", -1 );
if ($_FILES[$filename]['name'] !="")
{
$unique_id_query = strtoupper(substr(md5(uniqid(rand(), true)), 0 ,16));
$unique_add = $unique_id_query;
$unique_name = $destination.$codeupname.$unique_add;
//chmod($destnation,"777");
if($_FILES[$filename]["error"] > 0)
{
//echo $_FILES[$filename]["error"]." - error";
return -1; // file error
}
else
{
$uploadedfile = $_FILES[$filename]['tmp_name'];
$destination1 = $unique_name.$_FILES[$filename]['name'];
$path = "../".$destination1;
$result = move_uploaded_file($uploadedfile, $path);
if(!$result)
{
return -1;
}
else
{
echo $result;
//SET PROPER READ PERMISSIONS
$path2 = "/home/content/f/a/c/faccounting/html/".$destination1;
echo "PATH: ".$path2."<br />";
$result2 = chmod($path2, "0755");
echo "Result: ".$result2;
return $destination1; // returning image name and path
}
}
}
else
{
return -1; // no file persent
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
chmod
期望第二个参数为 int 并且您正在传递字符串。"0755"
转换为 int 是 755,而您想要0755
这是整数值的八进制表示形式 - 493。所以您需要更改
为
chmod
expects second argument to be int and you are passing string."0755"
converted to int is 755, while you want0755
which is octal representation of integer value - 493.So you need to change
into