Jump to content

Deleting Images From Folder On Server


twilitegxa

Recommended Posts

Can someone tell me how I can remove or delete an image from a folder on a server using PHP? I tried this:

 

 

unlink("http://midwestcreativeconsulting.com/jhrevell/wp-content/themes/twentyten_3/upload/" . $location);

 

 

before my delete MySQL statement, but I keep getting this error:

 

 

Warning: unlink() [function.unlink]: http does not allow unlinking in /home/midwestc/public_html/jhrevell/wp-content/themes/twentyten_3/removejewelry.php on line 22

 

Can anyone help and tell me how I can make it work?

Link to comment
Share on other sites

a URL is basically an address you give to a browser to get to a webpage. IE, http://www.example.com/page.php. Basically, you can't use the http protocol to get to a file to unlink. As PF said, if you could, someone would just continually delete everyones files. This would be pretty funny admittedly, but not good for the internet.

 

A system path can be two things, absolute, or relative. Relative is the path from the script you are running to the file you want to access (for deletion, changing, writing, whatever) Absolute is the absolute path to the file. For example, if I have the following folder structure

C:

--folder1

  --folder2

    file.php

    --folder3

      file_for_deletion.jpg

 

and my delete script is in file.php, the relative path would be "folder3/file_for_deletion.jpg", and the absolute path would be C:/folder1/folder2/folder3/file_for_deletion.jpg.

 

hope this helps

     

Link to comment
Share on other sites

So, just for clarification, if the file is on a server, how would an absolute path look then if you can't use http protocol? How can you say C:/? How could you know? Is it just best to use the relative path in this case maybe?

 

 

By the way, the relative path did work for me, so thank you everyone!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.