473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 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 3178
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Dino | last post by:
dear all, i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the...
1
by: Yon | last post by:
I've been trying to figure out how do i swap images that uploaded onto an object. I want to leave the object as it original form but the images that are uploaded are placed on the object.
13
by: LRW | last post by:
Having a problem getting a onSubmit function to work, to where it popsup a confirmation depending on which radiobutton is selected. Here's what I have: function checkdel() { if...
1
by: Esteban Felipe | last post by:
Hi, thanks for reading. I hope to find some help here before I commit suicide because this is driving me crazy. Please excuse me if this looks like a long post, but I hope that a complete...
3
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1, VS.NET (c#) .Net framework 1.1, IIS 5.1. In a...
15
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
12
by: Jon B | last post by:
Hi There! For some reasons, some images of my ASP.NET website are cannot be displayed in the browser (even tho they exists on the server). They are just normal JPG and PNG images and the website...
5
by: Neil | last post by:
I am getting time-out errors when I try to perform a simple delete on a linked server. The command is: Delete From MyTable Where PKID=12345 I have tried executing this command directly from...
11
by: comp.lang.php | last post by:
Once again, I thought my class method deleteZip() would do the trick, but it never deletes any .zip* file found in a directory: /** * Delete any latent ZIP files found in this album. This...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.