redarrow Posted May 23, 2006 Share Posted May 23, 2006 I am trying to delete any picture in a folder that is not in the database via the unset statement The idear is to plonk this in the folder with the members pictures to delete any picture not in the database.Please help.[code]<?//connect to the database$db=mysql_connect("localhost");mysql_select_db("members_pictures",$db);// select the field name $query="SELECT * FROM picture ";$result=mysql_query($query);// if statement where picture = 1 to the users idif(mysql_num_rows($result)==1){}else{// delete any other picture within that folder thats there.unset($picture);}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10235-unset-picture-in-folder-via-database-to-delete-pic/ Share on other sites More sharing options...
michaellunsford Posted May 23, 2006 Share Posted May 23, 2006 unset deletes variables, are you sure you aren't looking for unlink?If so, you could readdir() in a loop, and check the database for the filename.[code] $dir = realpath("."); //current folder. if($dh=opendir($dir)) { while(($file=readdir($dh))!=false) { $result=mysql_query("SELECT `picture_file_name` FROM `picture` WHERE `picture_file_name` = '$file'"); if(mysql_num_rows($result)<1) unlink($file); // no result DELETE FILE } closedir($dh); } else echo "directory error"; [/code]note, this is an example script and might not work just right for you. Oh, and this WILL delete files, so be careful. Test it someplace before you load it on your production site. Quote Link to comment https://forums.phpfreaks.com/topic/10235-unset-picture-in-folder-via-database-to-delete-pic/#findComment-38149 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.