tags:

views:

89

answers:

3

I have an old drupal site that I'd like to upgrade, but I need to move all the site data files (like jpgs, gifs, etc.) from /files to /sites/default/files.

I'd like to use a PHP script or just a MySQL command to find any instance of /files/* and change it to /sites/default/files/* (without messing up the string in the * part of the name, of course!).

Is this pretty easy to do? Any pointers on a function I could use?

+4  A: 

MySQL does have some built-in string replacement functions. How about something like this?

UPDATE table SET field = REPLACE(field,'/files/','/sites/default/files/');

There's other functions you can use for more complex replacements (ie. regular expressions) if you need as well.

zombat
Looks like it should work. I'll try that in my test environment and see how it goes!
Just used this value (for a few different tables), and everything works like a charm. Thanks!
No problem, glad it worked.
zombat
A: 

I'm pretty sure that it's just a case of changing the 'files' path in the Drupal configuration.

Garry
Doing so would update all the new files, and change Drupal's internal use of the files, but would not update all the nodes with links/references to the files.
A: 

If you're just changing the files table, you can do an UPDATE with SQL, like zombat said. If you have a significant number of other instances of the paths ( IE - full HTML node bodies and the like ) your best bet would be to export the DB to a text file (can do it with mysqldump or the export feature of PHPMyAdmin) and then just update the strings there - either with a suitable text editor, a command-line tool like sed or a bunch of interns.

Sean McSomething
Ah - this would be another good option. Might do this for the next site I need to work on!