I've two scripts, one to upload images, another to delete them. The
upload script works fine, but the delete script has permissions
trouble. How can PHP not have permission to delete an image it itself
uploaded?
Here is the delete script I'm using right now, and the error messages
I got below.
function deleteImage2() {
extract($config = getConfig());
global $pageRender, $forms, $io, $users, $links, $sql, $deleteImage;
$pathToImageFolder .= $deleteImage;
if (file_exists($pathToImageFolder)) {
$size = filesize($pathToImageFolder);
$permissions = fileperms($pathToImageFolder);
$owner = fileowner($pathToImageFolder);
startPage();
echo "This file is of this size: $size <hr>";
echo "This file has these permissions: $permissions <hr>";
echo "This file is owned by this user: $owner <hr>";
chmod($pathToImageFolder, 777);
if (unlink($pathToImageFolder)) {
echo "
<div class='mcForm'>
The image has been deleted. <br><br>
$pathToImageFolder
</div>
";
endPage();
} else {
echo "
<div class='mcForm'>
FAILED: For some reason the file couldn't be deleted.
</div>
";
endPage();
}
} else {
startPage("The file $pathToImageFolder doesn't seem to exist.");
endPage();
}
}
This is what I get:
This file is of this size: 3584
--------------------------------------------------------------------------------
This file has these permissions: 16895
--------------------------------------------------------------------------------
This file is owned by this user: 1002
--------------------------------------------------------------------------------
Warning: chmod failed: Operation not permitted in
/usr/local/www/vhosts/themadsun.com/htdocs/ppUtilityCode/mcAdminImages.php
on line 266
Warning: Unlink failed (Permission denied) in
/usr/local/www/vhosts/themadsun.com/htdocs/ppUtilityCode/mcAdminImages.php
on line 268
FAILED: For some reason the file couldn't be deleted.