Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 0.95 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Deleting Files In A Directory Based On A Table
  2. //listing all the ".jpg" files
  3. $arrayfiles=scandir("../images/Produk/");
  4.  
  5. //getting all the product list
  6. $sql="select * from produk";
  7. $produk=mysql_query($sql,$conn) or die("Error : ".mysql_error());
  8.  
  9. foreach($arrayfiles as $key=>$value)
  10. {
  11.   while($row=mysql_fetch_array($produk,MYSQL_ASSOC))
  12.   {
  13.     ///here is the part i've been confused of.
  14.   }
  15. }
  16.        
  17. $sql = "SELECT * FROM Produk";
  18. $result = mysql_query($sql);
  19. $existing_products = array();
  20. while ($row = mysql_fetch_array($result))
  21.   $existing_products[] = $row["id_produk"] . ".jpg";
  22.  
  23. $existing_images = array();
  24. foreach(glob("../images/Produk/*.jpg") as $v)
  25.   $existing_images[] = str_replace("../images/Produk/", "", $v);
  26.  
  27. $images_to_delete = array_diff($existing_images, $existing_products);
  28.        
  29. dir /b > filelist.txt (windows)
  30.        
  31. ls -1 > filelist.txt (linux)
  32.        
  33. foreach(glob('../images/Produk/*.jpg') as $file) {
  34.     if(is_file($file))
  35.         @unlink($file);
  36. }