php/iis file_get_contents permission denied for uploaded file

136 Views Asked by At

After successfully uploading a file to .../upload/tm/ I get an 500 error: permission denied when I want to read the contents of this file using file_get_contents.

$target = 'upload/' . $data['folder'] . '/' . $filename;
if (move_uploaded_file($file[$data['name']]['tmp_name'], $target)) {
    // $success = true;
    chmod($target, 0755);
}

According to my research, when moving the temp-file to .../upload/tm/, the permissions are not inherited and stay the same as in c:\windows\temp. So, I checked the permissions of both c:\windows\temp and .../upload/tm/. All of the indicated users have the same rw-permissions: IUSR, IIS_IUSRS, 'localmachine'$, 'localmachine'$/users, ...

I can solve this issue by manually re-apply the permissions of IUSR from the group or usernames in the Properties/Security tap of the parent folder .../upload/tm/ from which the permissions are inherited. But I need an better solution because I don't want to repeat this each time a file is uploaded.

All help is much appreciated.

Update

Somehow, when moving the file from outside the webfoldertree, the permissions are messed up. When I change the temporary upload folder to a branch of the same tree, the permissions are as suspected; the file is accessable and I can get its contents.

This solves the outcome of my problem, but the question is still for what reason I cannot get the contents with file_get_contents(), although the permissions look the same. I would rather keep the tempfolder on its original place.

0

There are 0 best solutions below