Jump to content

Finding pictures files not listed in my mysql database.


cyberspiritual

Recommended Posts

Hi everyone,

 

I'm trying to write a script to be able to delete picture file not used in my shop.

 

I have 2 size of pictures..one is called the item number followed by -01_S.gif and another one called the item number followed by -01_L.gif

 

So I wrote that:

<?php 
$resource = mysql_connect(localhost, XXXXXXX, XXXXXXX);
$db = mysql_select_db(XXXXXXXX, $resource)
or die ("Couldn't select database.");
$db;
// open the current directory by opendir
$handle=opendir(".");

while (($file = readdir($handle))!==false) {
$compteS = 0;
$compteL = 0;
$sqqql="SELECT * FROM products";  
$answer = mysql_query($sqqql);
while ($answer_data = mysql_fetch_array($answer) ) 
{ 

$model = $answer_data['products_model'];
$imageS = "$model-01_S.gif";
$imageL = "$model-01_L.gif";


if ($file!=$imageS)
echo"";
else
$compteS=$compteS+1; 

if ($file!=$imageL)
echo"";
else
$compteL=$compteL+1;

} 

if ($compteS==0)
echo"File $file should be deleted.<br>";
if ($compteL==0)
echo"File $file should be deleted.<br>"; 
}
closedir($handle);   
mysql_close($resource2); 
echo"finish";
?>

 

But when I run it, I get all file listed even if they are in my database... does anyone could suggest somehing?

 

Thank's

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.