Author Topic: Verify Files exist  (Read 7321 times)

0 Members and 1 Guest are viewing this topic.

Offline Taps

  • Newbie
  • *
  • Posts: 10
    • View Profile
Verify Files exist
« on: July 12, 2002, 03:55:27 AM »
Has anyone made a mod that can go through the databases and verify that files exist?  And if not, then delet them from the database.

Having many images online, it is easier to delete them in a large group than it is to delete them from the site one at a time.

Or at the very least, is it possible to change the edit images page to put checkboxes next to the ones you would like ot delete and have a single button at the bottom to delete the ones you selected.

Offline Kentorch

  • Newbie
  • *
  • Posts: 36
    • View Profile
Verify Files exist
« Reply #1 on: July 14, 2002, 02:20:35 PM »
greate idea ;)

Offline Taps

  • Newbie
  • *
  • Posts: 10
    • View Profile
Verify Files exist
« Reply #2 on: July 16, 2002, 06:23:27 AM »
Here is a very simple, very dirty, script that will go through, check all the images in your DB and see if th efile is there.  If not, then it will delete the row from the DB and delete the thumbnail.

There is no auth checking at all.  I actually cut and pasted a lot of this from the admin/users.php file.

No warranties.  If it melts your computer and renders you sterile, not my fault.

Code: [Select]

<?php
define
&#40;'IN_CP', 1&#41;;
define&#40;'ROOT_PATH', './../'&#41;;
require&#40;'admin_global.php'&#41;;

  // Delete Images ---------------------------------------------------------------------

    
$sql "SELECT image_id, cat_id, image_media_file, image_thumb_file 
            FROM "
.IMAGES_TABLE.
            order by image_id"
;
    
$result $site_db->query&#40;$sql&#41;;

    
while &#40;$row = $site_db->fetch_array&#40;$result&#41;&#41; &#123;
      
if &#40;!file_exists&#40;MEDIA_PATH."/".$row['cat_id'&#93;."/".$row['image_media_file'&#93;&#41;&#41; &#123;
    
$sql "DELETE FROM ".IMAGES_TABLE.
            WHERE image_id = "
.$row['image_id'&#93;;
      if &#40;file_exists&#40;THUMB_PATH."/".$row['cat_id'&#93;."/".$row['image_thumb_file'&#93;&#41; && !empty&#40;$row['image_thumb_file'&#93;&#41;&#41; &#123;
        
unlink&#40;THUMB_PATH."/".$row['cat_id'&#93;."/".$row['image_thumb_file'&#93;&#41;;
      
&#125;
    
echo $row['image_media_file'&#93;." does not exist.<BR>";
 echo "&nbsp;&nbsp;".$lang['images_delete_success'&#93;."<br />\n";
$del_images $site_db->query&#40;$sql&#41;;
      
&#125;
  &#125;
echo "Script Finished."
 
?>