Skip to content

Instantly share code, notes, and snippets.

@wojtha
Created June 13, 2011 22:18
Show Gist options
  • Save wojtha/1023869 to your computer and use it in GitHub Desktop.
Save wojtha/1023869 to your computer and use it in GitHub Desktop.
Drupal snippet - report missing files
<?php
$purge = FALSE;
$result = db_query('SELECT fid, filename, filepath FROM {files}');
$i = 1;
$out = "MISSING FILES:\n";
while ($f = db_fetch_object($result)) {
$dest = file_create_path($f->filepath);
if (!file_exists($dest)) {
$out .= $i++ . '. ' . $f->filepath;
if ($purge) {
if (db_query('DELETE FROM {files} WHERE fid=%d', $f->fid)) {
$out .= ' (cleaned)';
}
}
$out .= "\n";
}
}
if ($i == 1) {
$out .= "Congratulation, no file is missing!\n";
}
return $out;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment