473,671 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;

$pathToImageFol der .= $deleteImage;

if (file_exists($p athToImageFolde r)) {
$size = filesize($pathT oImageFolder);
$permissions = fileperms($path ToImageFolder);
$owner = fileowner($path ToImageFolder);

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($pathToIm ageFolder, 777);

if (unlink($pathTo ImageFolder)) {
echo "
<div class='mcForm'>
The image has been deleted. <br><br>
$pathToImageFol der
</div>
";
endPage();
} else {
echo "
<div class='mcForm'>
FAILED: For some reason the file couldn't be deleted.
</div>
";
endPage();
}
} else {
startPage("The file $pathToImageFol der 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.p hp
on line 266

Warning: Unlink failed (Permission denied) in
/usr/local/www/vhosts/themadsun.com/htdocs/ppUtilityCode/mcAdminImages.p hp
on line 268

FAILED: For some reason the file couldn't be deleted.
Jul 17 '05 #1
3 3202
On 6 Feb 2004 12:08:49 -0800, lk******@geocit ies.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;

$pathToImageFol der .= $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($p athToImageFolde r)) {
$size = filesize($pathT oImageFolder);
$permissions = fileperms($path ToImageFolder);
$owner = fileowner($path ToImageFolder);

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($pathToIm ageFolder, 777);

if (unlink($pathTo ImageFolder)) {
echo "
<div class='mcForm'>
The image has been deleted. <br><br>
$pathToImageFol der
</div>
";
endPage();
} else {
echo "
<div class='mcForm'>
FAILED: For some reason the file couldn't be deleted.
</div>
";
endPage();
}
} else {
startPage("The file $pathToImageFol der 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.p hp
on line 266

Warning: Unlink failed (Permission denied) in
/usr/local/www/vhosts/themadsun.com/htdocs/ppUtilityCode/mcAdminImages.p hp
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******@geocit ies.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
9097
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 data, imports it into a mySQL database and deletes the .csv-file after the import. so far, so good. but in some cases the cronjobs starts running when the file is not completely
1
1199
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
2353
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 (document.getElementById"].value=='1') { confirm('Are you sure you want to delete this file?'); } } ......
1
1451
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 explanation help you to help me :=) ....Let's start with some background: ..- I'm building an asp.net application that requires users to upload text files in cvs format with data exported from an AS-400. ..- The files will be something between 800kb...
3
3820
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 nutshell when testing my ASP.NET (localhost) apps images randomly don't load on the page. Examining the IIS logfile shows the missing images give 401 or 403 errors. Here's an example - 10:15:47 127.0.0.1 GET...
15
2821
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. Everything is the default settings I believe. IIS is running under Local System. In IIS the DefaultAppPool is running under Network Service. Annonymous access uses the account IUSR_JASMINE (machine name is Jasmine).
12
1629
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 has been working fine before. I tried re-upload the original files to the remote server but still no solution. Any ideas? Thank you all in advance!!!
5
9923
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 Query Analyzer, but it just times out. However, when I run it from QA against the server itself (rather than from my local server against a linked server), it executes immediately. Similarly, if I run the same SQL command through an ODBC linked...
11
5790
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 method is to be inherited by all listing classes to allow for * list-wide deletion of latent server-created ZIP files for security purposes *
0
8483
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8402
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8927
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8825
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7445
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.