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
}
}
chmodexpects second argument to be int and you are passing string."0755"converted to int is 755, while you want0755which is octal representation of integer value – 493.So you need to change
into