Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
i've come across one or two situations where i need to change the name of my site folder, i.e. to test it as a subdomain of a different domain from it's production domain. When this happens, all the filepaths in the file table are inaccurate, so images uploaded with imagefield, for example, don't work anymore. is there or could there be a way to refresh these filepaths?
Comments
Comment #1
quicksketchFileField won't provide this particular support. In general, this is a big Drupal problem if you want to move your files directory. Generally, the way I work around this is to always use symlinks for sites, rather than the real folders. For example, let's say you have a site called "example.com", but you run a development site at "dev.example.com" and you have a localhost setup at "localhost/example". You can avoid renaming the files path each time by simply setting up the file path at "sites/example/files", then using symlinks when you want to put the settings file at "sites/example/settings.php".
On your localhost: "localhost.example" => "example"
On your live site: "example.com" => "example"
On your dev site: "dev.example.com" => example"
In other words, the best solution is to simply not change your file path at all. Always leave it the same in the "real" directory, and use symlinks on each of your installations to refer to the real directory.
Comment #2
mattgilbert CreditAttribution: mattgilbert commentedok, thanks for the explanation.
Comment #3
epg CreditAttribution: epg commentedSo how do you set up a symlink for this on windows running apache? (local site)
And how do you set up a symlink for this on bluehost? (live site).
Can anyone help please? Noobzer here.
Comment #4
quicksketchWindows is not capable of creating symlinks unfortunately. However you can set up a VirtualHost in your httpd.conf file so that "http://example" goes directly to your live site, so the settings.php file in "sites/example/settings.php" will be read.
You'll need to SSH into your server using Putty or some other terminal program. Then use something like this: "ln -s [original file] [name of link]".
I'd suggest Googling for all other information, as this is not Drupal-specific knowledge.
Alternatively you don't *have* to use symlinks at all, you might just create "sites/example/files" and update your Drupal settings (at admin/settings/file-system) to use "sites/example/files" directly, rather than having a symlink.
Comment #5
epg CreditAttribution: epg commentedO.K. yeah so here's my problem.
I am indeed using virtual hosts on apache so cool to know I don't need to do anything on localhost.
As for bluehost, I figured I can run a cron job to send those commands (I don't have shell access) so that's o.k. to.
My problem: On bluehost, drupal is installed on public_html and my settings.php file is in the default directory, and my site is let's call it www.mylivesite.com
On localhost, drupal is installed in htdocs/drupal and my test site is in htdocs/drupal/sites/testsite
My file path is set to the default sites/testsite/files
So what exactly should I simlink to?
I tried
ln -s mylivesite.com/default testsite
but that doesn't get rid of duplicate paths, as a result of this I still get that my images are being looked for in the mylivesite.com/sites/default/files/sites/testsite/files/image.jpg path instead of mylivesite.com/sites/default/files/image.jpg.
Sorry for being such a thickhead but really all this linux and drupal stuff is very confusing to me!
Comment #6
epg CreditAttribution: epg commentedOh, also, I forgot to ask/clarify
In my local machine, I have my images in the htdocs/drupal/sites/testsite/files directory.
In my live site, I have my images in the public_html/sites/default/files directory.
So now what simlinks to what? Sorry linux newbie so don't quite understand what you meant by "original file". You mean file in the live server? As I explained if I just do
ln -s mylivesite.com/default testsite
or even
ln -s mylivesite.com/sites/default testsite
or even
ln -s mylivesite.com/sites/default/file testsite my images are still not found!
In all three cases drupal seems to still be looking for the images in the mylivesite/sites/default/file/sites/testsite/file directory. Please help!
Comment #7
quicksketchSo if you have your files in "htdocs/drupal/sites/testsite/files", then that means that you must have your Drupal file path saved at "sites/testsite/files" right? That's the key thing that we need to make consistent on the live server.
If this is the case, then you'd run:
ln -s ~/public_html/sites/default ~/public_html/sites/testtest
So "testtest" is the alias, and "default" is the original directory.
Comment #8
epg CreditAttribution: epg commentedHmm...well, unfortunately, that didn't work. The simlink wasn't even created!
O.K. heres what I did that seems to do the job (it is dirty, but at least it works)
I did:
rm all the symbolic links I tried to create to make sure I started clean.
Then I didn't create any symbolic links at all.
I just created a /sites/testsite/files directory in the public_html folder.
Suddenly it all worked!
I guess Drupal doesn't like the files to be in a different place in local vs site. It makes things a little odd, because my site is inside sites/default and my images are now in sites/someothernamethatisnotdefault, but at least it works.
I think this is a filething bug. Lots of people complain about it and it seems to confusionate lots of noobzers like me. Maybe there's a way in a future version to allow people to specify the file paths or make them tokens or summit so that you don't have to mirror the local machine directory structure exactly on live and vice-versa, as that is not always possible or practical.
Sorry just thinking aloud there, but at least it looks like it's working now.
Thanks for all the hints!
Comment #9
quicksketchThe storage of files in the "files" table is handled entirely by Drupal core, so there's nothing FileField can do to adjust for that. However this has been fixed in Drupal 7 already anyway, so all we have to do now is wait for D7 to be finalized (FileField has been moved to core in D7 also).