469,319 Members | 2,320 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

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 2935
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.