Relocating the files directory
Submitted by clemens on Tue, 2009/02/03 - 11:10am
Trying best practices I occasionally move the files directory from DRUPAL_ROOT/files/my-site.com to DRUPAL_ROOT/sites/my-sites/files
Doing this has some implications for the files table content. All file-path are pointing to the wrong location.
Quick solution for this is an mysql replace update query.
select replace(filepath, 'files/my-site/', 'sites/my-site/files/') from files;
# update files set filepath=replace(filepath, 'files/my-site/', 'sites/my-site/files/')"
Or through drush
drush sql query "select replace(filepath, 'files/my-site/', 'sites/my-site/files/') from files"
# drush sql query "update files set filepath=replace(filepath, 'files/my-site/', 'sites/my-site/files/')"
See http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_re... for more examples
free form:
Comments
for public <-> private too
You can also use this technique if you switch from the public to private (or vice verse) filesystem. I used a few more rules though. You'll also need to do this to any other tables in which you might store a URL to the file system