"Changing the file system path after files have been uploaded may cause unexpected problems on an existing site."

Boy howdy! Is there a quick way to deal with this? I did follow the directions but have a problem.

I have a multisite server. To avoid upgrade snafus, I symlink from, e.g., /drupal/drupal-5.7/files to /drupal/drupal.files.
Then each host gets its own file folder, e.g., /drupal.files/site1.files

Sites work fine but on one of them (call it siteX), I forgot to set the filesystem at the start, just used the default. I would like to clean that up.
I created /drupal.files/siteX.files and COPIED its files in there. They are mostly PDFs - file attachments in Biblio records (as in Biblio module).
Then I set the site X filesystem to drupal.files/siteX.files.

Drupal then changed all the URLs of the attached files in my Biblio records to: mysite.com/files/siteX.files/files/siteX.files/whatever.pdf
Note the extra "files/siteX.files" So file not found.

I tried changing one URL in the Biblio 'file attachment' field but Drupal didn't recognize the change. [I forget details]
I was able to delete the old file, using Biblio , and upload another copy, but (a) this is laborious and (b) Drupal (or Biblio module) adds "_0" to the name of the file, even when the old file has been previously deleted and I'm supposedly starting from scratch.

I was tempted to use sql ( e.g., "update files set filepath to newplace where filepath like oldplace") but caution won out.

I'm not sure if this is Drupal issue, or a Biblio issue (as the files are Biblio attachments).

If anyone's been able to cleanly change a filesystem setting, would you kindly share your experience?
Thank you.

Comments

VM’s picture

The only way I know to do it is to go through each record in the DB changing them manually. I suppose if you see a pattern while there you can write a SQL snippet to change them as well.

Anonymous’s picture

Thank you, oh well... it's supposed to be do-able.

Do you have any idea why Drupal (or maybe it's Biblio) insists on creating a duplicate file, e.g.,

mypaper.pdf
mypaper_0.pdf

even if I first delete the attached file (nicely, via the Biblio module) & then upload the file again ?

Doesn't all this have implications for moving a test site to a public site?
Or would you just point the file system of the final, public site to the same directory the test site used?

Anonymous’s picture

After moral support from Caroline Schnapp at 11heavens.com (good advice dispensed by a good writer) -- was encouraged to muck directly with mysql.

- first changed filesystem path
- then moved files to where I wanted them
- then this:
UPDATE files SET filepath = REPLACE(filepath,'files/','newlocation');

This worked, at least, a basic listing of Biblio records has correct URLs to download PDFs.

I may find that Biblio is confused by the change, but so far so good.

Lesson so far: it is apparently not enough to update the filesystem through Drupal's interface and put files in new place; you have to update the database directly.

VM’s picture

Lesson so far: it is apparently not enough to update the filesystem through Drupal's interface and put files in new place; you have to update the database directly.

That is correct. Unfortunately when a change is made to settings, it only takes affect on "new" file uploads not uploads made previous to the change.

The same holds true with things like input formats and teaser lengths. If these settings are changed the nodes have to be reopened and resaved so that the changes take effect on node created before the changes were made.

Hats off to Caroline for helping you get through updating the DB directly.

mosa’s picture

I was having this problem as well after moving everything to a test site before upgrades. None of my images or files would work anymore. Inspection of the file system confimed that all the files had been copied over fine and also had correct permissions.

I checked all of Drupal's system/file path settings and made sure I had updated them. I even tried disabling and re-enabling the image/image assist modules (before I realized this was affecting PDFs as well). Couldn't find any warnings about this in the docs that go through creating a test site.

Then I sat down and started going through the database looking for our old URL (since it was the only option left). I could see the incorrect paths just below the file attachment info in each image node using Drupal's front end, and knew that the URL had to be referenced wrongly somewhere as it was still looking for our old one.

Then I found this post and realized which table I needed to be looking in, and used the Query example above.

Thanks a million, this was very helpful!

omnyx’s picture

Great!

GuillaumeDuveau’s picture

Thanks a lot for this post ! I just switched from the private method in a server-only readable directory to the public method with files/ without any problem !

Aren Cambre’s picture

That worked for me, too! Certainly there has to be a better way?

I just opened #361099: Make file storage more resilient and secure.

vallab444’s picture

Thanks a lot, meles, for this tip. I was struggling with the taxonomy image display after I changed the file system. It works now.

-Vallab

marcel.jtf’s picture

@meles
Thanks for the explanation. The UPDATE query worked perfect on our D7 multi-site install.

After we did domain name changes none of the uploaded images/files were referencing the old folder paths.

rjerome’s picture

Just for the record, the biblio module uses the Drupal Upload module to handle file attachments, so what ever happened it's not my fault :-)

Ron.

thePanz’s picture

I've created a module for moving files when you change Drupal filesystem path.
If you're interested in testing ... let me know!

Regards

-thePanz-

thePanz’s picture

I've published my module (file_mover) in my blog: http://thepanz.netsons.org/post/cambiamento-filesystem-drupal-filemover-...

Feel free to download and test it. I've used it on my WAMP and LAMP servers and it's working fine.
Let me know

Regards

-thePanz-

izmeez’s picture

@thePanz Thanks for the instructions in this thread.

Sorry that I'm stuck with English, I was wondering if you have instructions for the module in English ?

Does this module just change the filepaths in the SQL database ?
I presume it is not moving the files on the server and it is still necessary to create the new files directory and move the files to the new directory.

Also is the module changing other system filepaths such as used on the theme configuration page(s) ?
Do the theme configuration filepaths even need to be changed?
I am guessing when going from public to private file system they do need to be changed from "site/files/logo.gif" to "system/files/logo.gif", but maybe that is not necessary?

Thanks,

Izzy

savedario’s picture

Firstly, thanks for this.

When I recently moved my Drupal site from one account/domain to another, I notice a second problem with user photos.
The REPLACE statement above has to be repeated a second time:

UPDATE users SET picture = REPLACE(picture,'
','');

Oooops. I noticed too late this thread was about Drupal 5.x
My addition is for Drupal 6.x (I am not sure whether there's a difference, but...)