Created
May 13, 2011 01:04
-
-
Save wojtha/969769 to your computer and use it in GitHub Desktop.
Replace non-existent files with empty file using Drupal {file} table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// REPLACE? | |
$replace = FALSE; | |
// path to empty file | |
$source = 'files/empty.png'; | |
// RUN | |
$result = db_query('SELECT fid, filename, filepath FROM {files}'); | |
$src = file_create_path($source); | |
$src_exists = file_exists($src); | |
$i = 1; | |
while ($f = db_fetch_object($result)) { | |
$dest = file_create_path($f->filepath); | |
if (!file_exists($dest)) { | |
$out .= $i++ . '. ' . $f->filepath . "\n"; | |
if ($replace && $src_exists) { | |
copy($src, $dest); | |
chmod($dest, 0664); | |
db_query("UPDATE {files} SET origname='%s' WHERE fid=%d", 'empty.png', $f->fid); | |
} | |
} | |
} | |
return $out; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment