Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2005
    Location
    Utah
    Posts
    65
    Thanks
    6
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,332
    Thanks
    60
    Thanked 526 Times in 513 Posts
    Blog Entries
    4
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    New Coder
    Join Date
    May 2005
    Location
    Utah
    Posts
    65
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,332
    Thanks
    60
    Thanked 526 Times in 513 Posts
    Blog Entries
    4
    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).
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    Local Hero (12-21-2012)

  • #5
    New Coder
    Join Date
    May 2005
    Location
    Utah
    Posts
    65
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •