Skip to content

Instantly share code, notes, and snippets.

@delphian
Last active December 29, 2015 02:48
Show Gist options
  • Save delphian/7602731 to your computer and use it in GitHub Desktop.
Save delphian/7602731 to your computer and use it in GitHub Desktop.
When working on a drupal site on localhost instead of production often there are no files in the localhost files directory. This script will create (touch) empty filenames that match all files managed by the drupal database.
<?php
/**
* @file
* When working on a drupal site on localhost instead of production often
* there are no files in the localhost files directory. This script will
* create (touch) empty filenames that match all files managed by the
* drupal database. In a multi-site environment this script should be
* located in the drupal root.
*
* bryan.hazelbaker@gmail.com
*/
// Needed for multisite bootstrap.
$_SERVER['HTTP_HOST'] = 'my-site-name.com';
$_SERVER['SCRIPT_NAME'] = '/' . 'touch-all-fids.php';
// Bootstrap drupal.
$_SERVER['REMOTE_ADDR'] = '';
define('DRUPAL_ROOT', '/absolute/path/to/drupal/root');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
function drupal_touch_all_fids() {
$fids = array();
$result = db_query('SELECT * FROM file_managed');
foreach($result as $row) {
print($row->fid . "\r");
touch(drupal_realpath($row->uri));
}
}
drupal_touch_all_fids();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment