Jump to content

reading contents of folder into array and comparing to sql results


Zeradin

Recommended Posts

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.

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,

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.