Zeradin Posted September 18, 2008 Share Posted September 18, 2008 I have folders where people upload images, but they can change. i was wondering if i could make a "purge script" that looks at all the files in the folder and then looks at all the sql values of image names and them deletes anything that doesn't have a match. Can someone push me in the right direction? I don't need the whole script i just don't know where to start. Link to comment https://forums.phpfreaks.com/topic/124802-reading-contents-of-folder-into-array-and-comparing-to-sql-results/ Share on other sites More sharing options...
uniflare Posted September 18, 2008 Share Posted September 18, 2008 Ok that can be quite simple i have recently made something extremely similar. Thing is you shouldn't really need it, if your users are uploading/moving and deleting images, you would add into those scripts the code that changes the mysql. Upload -> (Add MySQL Row) Move -> (Update MySQL Row) Delete -> (Remove MySQL Row) All these 3 functions should be done by php scripts that people have to login to or anyone could go tramping through your galleries. Hope this helps, Link to comment https://forums.phpfreaks.com/topic/124802-reading-contents-of-folder-into-array-and-comparing-to-sql-results/#findComment-644711 Share on other sites More sharing options...
Garethp Posted September 18, 2008 Share Posted September 18, 2008 The script you need would be along these lines of logic Read contents like this $dir = '/my_directory_location'; $files = scandir($dir); $i = 0; foreach($files as $ind_file) { $Filesar[$i] = $files; $i ++; } then foreach($Filesar as $v) { //check $v against mysql database if(mysql_num_rows($Query)) { unlink ($v); } } Or something along those lines Link to comment https://forums.phpfreaks.com/topic/124802-reading-contents-of-folder-into-array-and-comparing-to-sql-results/#findComment-644719 Share on other sites More sharing options...
Zeradin Posted September 18, 2008 Author Share Posted September 18, 2008 thanks guys, i'll work on this in a little while and see if i can get it working! Link to comment https://forums.phpfreaks.com/topic/124802-reading-contents-of-folder-into-array-and-comparing-to-sql-results/#findComment-644751 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.