newbreed65 Posted December 27, 2008 Share Posted December 27, 2008 Hi Everyone Is there a function to delete a folder and its content by just saying you want to delete the folder? I currently I know how to do it by deleteing every file with unlink and then deleting the folder with rmdir. I was just wondering if there was well a less pain in the arse way. its for deleting a photo album folder Quote Link to comment https://forums.phpfreaks.com/topic/138562-deleting-a-full-folder-dir/ Share on other sites More sharing options...
Philip Posted December 27, 2008 Share Posted December 27, 2008 I'm 99.99% sure that you have to delete each file individually, then delete the folder when it's empty. However, depending on your system setup, you might be able to get away with some server commands. Example: <?php $pathto = '/home/user/public_html/images/iwanttodeletethis/'; system ("rm -Rf $pathto") ; ?> That should delete the folder and all the contents, given your running the correct os Quote Link to comment https://forums.phpfreaks.com/topic/138562-deleting-a-full-folder-dir/#findComment-724517 Share on other sites More sharing options...
newbreed65 Posted December 27, 2008 Author Share Posted December 27, 2008 hmm I guess Ill have to just do it by deleting the files first :-/ Quote Link to comment https://forums.phpfreaks.com/topic/138562-deleting-a-full-folder-dir/#findComment-724523 Share on other sites More sharing options...
HoTDaWg Posted December 27, 2008 Share Posted December 27, 2008 hmmm im not to sure if itll delete the files as well but you could try: <?php rmdir("path/folder_name"); ?> hope this helps. EDIT: im sorry this is of no use to you, i re-read your post. my mistake if a mod is around hopefully they could delete this post? Quote Link to comment https://forums.phpfreaks.com/topic/138562-deleting-a-full-folder-dir/#findComment-724607 Share on other sites More sharing options...
newbreed65 Posted December 27, 2008 Author Share Posted December 27, 2008 No sadly the folder has to be empty first...below is currently the code I have which deletes it all. I was just hoping that there might have been a function out there that would have done the same thing just would have mess around deleting all the files from the folder first $getpic = "SELECT * FROM movieimages WHERE movie_id = $mid"; $result = mysql_query($getpic) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $DelImage ="images/" . $mid . "/" . $row ['image_id'] . ".jpg"; $DelThumb = "images/" . $mid . "/thumbs/" . $row ['image_id'] . ".jpg"; $dirImage = "images/" . $mid; $dirThumb = "images/" . $mid . "/thumbs"; unlink($DelImage); unlink($DelThumb); } rmdir($dirThumb); rmdir($dirImage); Quote Link to comment https://forums.phpfreaks.com/topic/138562-deleting-a-full-folder-dir/#findComment-724609 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.