EchoFool Posted June 15, 2009 Share Posted June 15, 2009 I have a script to delete a directory plus all its contents inside the directory before hand... but i get an error every time i try it..... This is my code: <?php $ID = strtolower(mysql_real_escape_string(stripslashes($_POST['ID']))); $mydir = "images/$ID/"; $d = dir($mydir); while($entry = $d->read()) { if ($entry!= "." && $entry!= "..") { unlink($entry); } } $d->close(); rmdir($mydir); ?> But i keep getting this response : Warning: unlink(1245096028.jpg) [function.unlink]: No such file or directory in listings.php on line 72 Warning: unlink(1245096033.jpg) [function.unlink]: No such file or directory in listings.php on line 72 Warning: unlink(1245096037.jpg) [function.unlink]: No such file or directory in listings.php on line 72 Warning: unlink(1245096041.jpg) [function.unlink]: No such file or directory in listings.php on line 72 Warning: unlink(1245096045.jpg) [function.unlink]: No such file or directory in listings.php on line 72 Warning: unlink(1245096050.jpg) [function.unlink]: No such file or directory in listings.php on line 72 Warning: unlink(1245096054.jpg) [function.unlink]: No such file or directory in listings.php on line 72 Warning: unlink(1245096062.jpg) [function.unlink]: No such file or directory in listings.php on line 72 Warning: unlink(1245096065.jpg) [function.unlink]: No such file or directory in listings.php on line 72 Warning: rmdir(images/13/) [function.rmdir]: Directory not empty in listings.php on line 76 My directory is correct otherwise i wouldn't get the final error of: Warning: rmdir(images/13/) [function.rmdir]: Directory not empty in listings.php on line 76 What have i got wrong? Hope you can help. Link to comment https://forums.phpfreaks.com/topic/162274-solved-empty-directory-delete-directory-afterwards/ Share on other sites More sharing options...
benphelps Posted June 15, 2009 Share Posted June 15, 2009 You can always just try this. $ID = strtolower(mysql_real_escape_string(stripslashes($_POST['ID']))); $mydir = "images/$ID/"; system("rm ${mydir} -rf"); but to answer your question, you need to add the directory in with the unlink. $ID = strtolower(mysql_real_escape_string(stripslashes($_POST['ID']))); $mydir = "images/${ID}/"; $d = dir($mydir); while($entry = $d->read()) { if ($entry!= "." && $entry!= "..") { unlink($mydir.$entry); } } $d->close(); rmdir($mydir); Link to comment https://forums.phpfreaks.com/topic/162274-solved-empty-directory-delete-directory-afterwards/#findComment-856538 Share on other sites More sharing options...
Alex Posted June 15, 2009 Share Posted June 15, 2009 Or try: while (($entry = $dir->read()) !== false) Link to comment https://forums.phpfreaks.com/topic/162274-solved-empty-directory-delete-directory-afterwards/#findComment-856540 Share on other sites More sharing options...
EchoFool Posted June 15, 2009 Author Share Posted June 15, 2009 Works a treat thanks guys Link to comment https://forums.phpfreaks.com/topic/162274-solved-empty-directory-delete-directory-afterwards/#findComment-856570 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.