Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-21-2012, 01:46 AM   PM User | #1
Local Hero
New Coder

 
Join Date: May 2005
Location: Utah
Posts: 58
Thanks: 6
Thanked 0 Times in 0 Posts
Local Hero is an unknown quantity at this point
unlink not working

I have 100's of images that users upload onto my site. I have a page to view them and next to each image I want a DELETE button or text to delete the image from my server. Below is the code the has the file name, then DELETE and then the image on the next line.

PHP Code:
$handle=opendir("./content/uploaded");
                  {
while ((
$file readdir($handle))!==false

 
$file_list .=  $file " <a href='imagecheck2.php?delete=/content/uploaded/" $file "'> DELETE </a><br><a href='./content/uploaded/" $file "' target='blank'> <img src=./content/uploaded/" $file " width=400></a><br>"; }

closedir($handle);
echo 
"$file_list";
    } 
The DELETE makes the site go to http ://www.mysite.com/imagecheck2.php?delete=/content/uploaded/redball.jpg

PHP Code:
  if(isset($_GET['delete'])) 

   
$delete_file $_GET['delete']; 
  
unlink("$delete_file"); 
{ if(
unlink$delete_file))
   { echo (
"$delete_file has been deleted");}
   else {echo( 
"unable to delete $delete_file");}
}

I keep getting "unable to delete http://www.mysite.com/imagecheck2.php?delete=/content/uploaded/redball.jpg"

I can't find a free FTP software that will let me delete the image files where I can view them easily so I'm trying to get this to work instead. Nothing so far today, Any help is appreciated.
Local Hero is offline   Reply With Quote
Old 12-21-2012, 01:51 AM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Local Hero View Post
I keep getting "unable to delete http://www.mysite.com/imagecheck2.php?delete=/content/uploaded/redball.jpg"
Thats not a complete error message. It's lacking the other details which I would suggest you post. It's almost certainly a file path issue but from what you've posted so far it looks like you're trying to delete the file via a url using the http protocol and that simply can't be done.

Quote:
Originally Posted by Local Hero View Post
I can't find a free FTP software that will let me delete the image files where I can view them easily so I'm trying to get this to work instead. Nothing so far today, Any help is appreciated.
Google filezilla. Thats a free FTP program and usually turns up easily in google so you can't have searched very well If you mean you want one that will preview the images via FTP, it doesn't exist. Why? Because it would have to download every image in order for you to preview it.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 12-21-2012, 02:02 AM   PM User | #3
Local Hero
New Coder

 
Join Date: May 2005
Location: Utah
Posts: 58
Thanks: 6
Thanked 0 Times in 0 Posts
Local Hero is an unknown quantity at this point
That's the message I get because that's what I programed the code to say when it failed.

Are you saying that I cannot delete a file, or delete it from the URL? I can't figure out another way to delete the file from a button/link.

I did look at Filezilla, but I wanted to view images. I understand what you're saying, so I wanted to build this page for myself to remove images that I'm finished with.

Is there a better way to unlink the file with a button/link next to the image?
Local Hero is offline   Reply With Quote
Old 12-21-2012, 02:19 AM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Local Hero View Post
That's the message I get because that's what I programed the code to say when it failed.
Ah ok, I had it in my head it was a PHP error message. Right in that case you're definitely using a url which is good to know.

Quote:
Originally Posted by Local Hero View Post
Are you saying that I cannot delete a file, or delete it from the URL?
No of course you can't. That would be a MASSIVE security breach wouldn't it. Imagine if I could go to your website and just delete every page using a php script on my server and the url of your pages. That is the very point of http - it's pretty much a request and response protocol and thats it.

There are apparently some http servers that will allow a delete request but I've never used one, seen one or actually heard of anyone insane enough to run one. I would imagine there are uses for them but for general website hosting it's not used for the reasons above.

Quote:
Originally Posted by Local Hero View Post
I can't figure out another way to delete the file from a button/link.
You need to use a local file system path instead.

Say your script is in your public_html folder and your image file is image.jpg and it's also in your public_html folder then you would:
unlink('image.jpg');

If it's in public_html/images/ then:
unlink('images/image.jpg');

and so on and so forth.
../ means up one level.
./ means this directory

Hope that helps (PS off to bed now so if you've anymore questions someone else will need to answer).
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
Local Hero (12-21-2012)
Old 12-21-2012, 03:49 AM   PM User | #5
Local Hero
New Coder

 
Join Date: May 2005
Location: Utah
Posts: 58
Thanks: 6
Thanked 0 Times in 0 Posts
Local Hero is an unknown quantity at this point
Got it! It makes sense now why you wouldn't want it to delete files from HTTP. At the time, it seemed like it could work Thanks!
Local Hero is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:13 PM.


Advertisement
Log in to turn off these ads.