471,887 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

I can't delete images that I've uploaded - how do permissions work?

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.
Jul 17 '05 #1
3 3069
On 6 Feb 2004 12:08:49 -0800, lk******@geocities.com (lawrence) wrote:
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; How's this set up before adding the image name??? Are you ok for
trailing slashes? Whatever, if this is the file to be deleted, the
name is a bit confusing!

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.


Jul 17 '05 #2
I'm fairly sure I've done all the error checking that I need to. What
strikes me now is that the permssions are set to 16895 . That's what
fileperms() returns. What kind of permissions is that?

Jul 17 '05 #3
lk******@geocities.com wrote:
I'm fairly sure I've done all the error checking that I need to. What
strikes me now is that the permssions are set to 16895 . That's what
fileperms() returns. What kind of permissions is that?


print substr(sprintf('%o', '16895'), -4);

This prints out '0777', so you should be able to remove the files...

Get the name of the apache user (e.g. by checking uploaded files with an ftp
client) and try to remove them after you have made yourself the owner of the
files by calling chown() after you have uploaded them.
HTH;
JW

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by LRW | last post: by
3 posts views Thread by Simon | last post: by
15 posts views Thread by David Thielen | last post: by
12 posts views Thread by Jon B | last post: by
11 posts views Thread by comp.lang.php | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.