473,915 Members | 5,929 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 3213
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
9129
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
1211
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
2377
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
1466
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
3836
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
2849
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
1657
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
9947
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
5831
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
10039
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
10928
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...
0
10543
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7259
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5944
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4779
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
3
3370
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.