Advertisement
carbonize

Orphaned Image Files

Sep 18th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2.  
  3. $directory = dirname(__FILE__);
  4. if (glob($directory . '/public/img-*.[jpgb][pnim][gfp]') != false)
  5. {
  6.   $imgcount  = count(glob($directory . '/public/img-*.jpg'));
  7.   $imgcount += count(glob($directory . '/public/img-*.bmp'));
  8.   $imgcount += count(glob($directory . '/public/img-*.png'));
  9.   $imgcount += count(glob($directory . '/public/img-*.gif'));
  10. }
  11. else
  12. {
  13.   $imgcount = 0;
  14. }
  15.  
  16. if ($imgcount > 0)
  17. {
  18.   //
  19.   // Now we connect to the MySQL server and select the database
  20.   //
  21.   include_once $directory.'/admin/config.inc.php';    
  22.   if ($dbc = @mysql_connect ($GB_DB['host'], $GB_DB['user'], $GB_DB['pass']))
  23.   {
  24.      if (!@mysql_select_db ($GB_DB['dbName'], $dbc))
  25.      {
  26.         die ('<p>Could not select the database because: <b>'.mysql_error().'</b></p></div></body></html>');
  27.      }
  28.   }
  29.   else
  30.   {
  31.      die ('<p>Could not connect to MySQL because: <b>'.mysql_error().'</b></p></div></body></html>');
  32.   }
  33.  
  34.   //
  35.   // End of MySQL database information check
  36.   //  
  37.   $our_query = 'SELECT COUNT(p_filename) AS totalpics FROM '.$table_prefix.'_pics';
  38.   $result = mysql_fetch_assoc(mysql_query($our_query, $dbc));
  39.  
  40.   if($imgcount > $result['totalpics']) {
  41.     echo 'You have ' . ($imgcount - $result['totalpics']) . ' orphaned image files in your public directory.';
  42.   }
  43. }
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement