twilitegxa Posted June 1, 2011 Share Posted June 1, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/238057-deleting-images-from-folder-on-server/ Share on other sites More sharing options...
Rifts Posted June 1, 2011 Share Posted June 1, 2011 make sure the folder/file has correct permissions Quote Link to comment https://forums.phpfreaks.com/topic/238057-deleting-images-from-folder-on-server/#findComment-1223321 Share on other sites More sharing options...
twilitegxa Posted June 1, 2011 Author Share Posted June 1, 2011 I tried setting the folder with the images in it to 777. Do I need to set any other folders? The images within the folder are also set to 777. Quote Link to comment https://forums.phpfreaks.com/topic/238057-deleting-images-from-folder-on-server/#findComment-1223323 Share on other sites More sharing options...
PFMaBiSmAd Posted June 1, 2011 Share Posted June 1, 2011 You have to use a file system path, not a URL. If you could use the http protocol to delete files off of web servers, just about every web site on the planet would have already had all their files deleted. Quote Link to comment https://forums.phpfreaks.com/topic/238057-deleting-images-from-folder-on-server/#findComment-1223327 Share on other sites More sharing options...
twilitegxa Posted June 1, 2011 Author Share Posted June 1, 2011 Can you explain? I'm not sure how to do that. Can you give examples or tell me how I find out the file system path? Quote Link to comment https://forums.phpfreaks.com/topic/238057-deleting-images-from-folder-on-server/#findComment-1223775 Share on other sites More sharing options...
Tenaciousmug Posted June 1, 2011 Share Posted June 1, 2011 I'm not sure if this is what he means, but I decided to try and help anyways: unlink("/home1/midwestcreativeconsulting/public_html/jhrevell/wp-content/themes/twentyten_3/upload/" . $location); Quote Link to comment https://forums.phpfreaks.com/topic/238057-deleting-images-from-folder-on-server/#findComment-1223776 Share on other sites More sharing options...
mikesta707 Posted June 1, 2011 Share Posted June 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/238057-deleting-images-from-folder-on-server/#findComment-1223778 Share on other sites More sharing options...
twilitegxa Posted June 3, 2011 Author Share Posted June 3, 2011 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/238057-deleting-images-from-folder-on-server/#findComment-1224460 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.