multi-site image paths

jmoses - November 20, 2008 - 01:51

im having issues with image paths between a development site and production site. im also using multi-site installation. im using fckeditor and the built-in file browser to upload files and use them in content.

Here is the situation:

if i have site.com and dev.site.com, then i have /sites/site.com/files and /sites/dev.site.com/files

so on the dev site, if i add an image into some content, its gets put in like this
<img src="/sites/dev.site.com/files/image.jpg" />

i expeced that when i migrate everything to the production site that the image would be like this
<img src="/sites/site.com/files/image.jpg" />
but it is not, it still points to /sites/dev.site.com/files/image.jpg

after reading through some documentation and forums, i tried changing the image paths to just be /files/image.jpg
expecting that if you are on site.com it will look in /sites/site.com/files/image.jpg
and if your on dev.site.com it will look in /sites/dev.site.com/files/image.jpg
but it does not
no image shows up when using /files/image.jpg

hopefully all that makes sense to some body.

is this desired behavior even possible?

As you found out yourself,

cog.rusty - November 20, 2008 - 03:32

As you found out yourself, the default locations of "files" is a bad choice for a multisite. If the links are in the content and they contain a domain name, Drupal can't do much about it.

A better idea is:
files (directly under drupal)
files/site1-alias
files/site2-alias
etc

The aliases can be short mnemonic names, independent from the real domain names, so that you can use the same ones when you move the site. Just specify these paths in admin/settings/file-system.

If for some reason you want your files under sites/example.com/files then, again, you can create a files/site-alias symlink under drupal and use that to access a site's files indirectly. Although personally I don't see the point.

Mmm. This is an issue I was

dman - November 20, 2008 - 03:42

Mmm.
This is an issue I was going to do a small tutorial on (I have the draft somewhere)

Nowadays, when doing a dev and production site that needs to be embedding file paths, I:

- create /sites/sitename (THIS DOES NOT WORK BY ITSELF)
- create a symlink /sites/site.on.devserver -> /sites/sitename (which does work, and I boot from there)
- After install, I set the drupal files path to /sites/sitename/files

All links I create point to the phantom/cannonic site dir.

When I deploy, I upload the /sites/sitename folder, and create a new symlink on the destination
/sites/site.realname.com -> /sites/sitename

It's a bit tricky, but it works. When you have the ability to symlink.

There is also a workaround available to patch this issue. Check out
http://drupal.org/project/pathologic
or maybe
http://drupal.org/project/pathfilter
http://drupal.org/project/url_replace_filter

.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |

Hey Dan, I was thinking that

cog.rusty - November 20, 2008 - 03:51

Hey Dan, I was thinking that because these solutions with symlinks are not viable as a default, maybe the idea of site aliases deserves more attention in the future.

For example, a future Drupal version could stop using site directories with real domain names, put the real domain names in a configuration file, and produce aliases from them for the site directories.

Hm. Or domain/settings.php

dman - November 20, 2008 - 04:31

Hm.
Or domain/settings.php can include('../aliased_site/settings.php') ?
:-?

.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |

/sites/files/site1.com

jmoses - November 21, 2008 - 15:10

i did something similar to what cog.rusty suggested

i created a files directory in the sites directory, and created a folder for each site in there.

/sites/files/site1.com
/sites/files/site2.com

then updated the File system path (Admin -> Site configuration -> File system)

do both dev.site.com and site.com use /sites/files/site.com

I put it in the /sites/ directory just to keep the non-Drupal stuff contained to one directory.

Thanks for your help!

When I create this structure,

nwwoman - September 30, 2009 - 15:23

POSTSCRIPT: Just realized I need more coffee. The new file folder go inside the main file folder. Duh.

When I create this structure, is there a reason I have to create the files/directly under Drupal folder? After I created it, it is now sitting there empty, wondering why it exists. My thinking is hit delete but thought I'd ask here first.

Now, all of my images, imagecache stuff and pdfs are under the sites/site1/files folder. Moving all of these t'aint gonna be fun.

I've got a similar issue -

cgjohnson - July 6, 2009 - 22:19

I've got a similar issue - but my problem is I don't want visitors to a multisite domain to click on an image URL and get mainsite.com/sites/site.com/files/images/...

I want them to see the URL as www.site.com/files/images (and not the mainsite.com URL).

is there an easy way to do this? I bet there is. Help appreciated. thanks.

subscribe

nwwoman - August 31, 2009 - 18:50

subscribe

subscribe

knoebel - September 28, 2009 - 16:49

subscribe

Anyone reading this message

nwwoman - November 24, 2009 - 04:23

Anyone reading this message thread might want to read about the patch for this files problem that will be in D7 but is now available for D6. It will not be back-ported to D6 as its stable but you can add the patch yourself. See: http://drupal.org/node/231298 Post 83 has the patch (http://drupal.org/node/231298#comment-1420180 )

With this patch and the addition of a sites.php file, all images and files use the same directory path no matter if you are on local or live -- without the use of symlinks.

 
 

Drupal is a registered trademark of Dries Buytaert.