1. cck 6.x-2.1
2. imagefield 6.x-3.0-alpha4
3. full read/write permissions (site is in dev on my local win xp box)
4. public files

I'm using two different site folders on my Drupal install (sites/default, and sites/site2). The content type is called "homepage".

When a user on site "site2" uploads an image to a filefield, the file ends up in sites/site2/files/images/homepage/

When back on site "default", when trying to view the node (on single node display, views output and node edit pages at the least), the path given to display the image (using the default Image handler) is sites/default/files/sites/site2/files/images/homepage/, which does not exist, and seems like a bug (or is at least very odd).

The expected results would be one of either (in order of preference):

- files uploaded go into default site files folder always, and path to images is correct (/sites/default/files/images/homepage)
- files uploaded go to site specific files folder, and when back on the other site, the correct path is provided (in this case, /sites/site2/files/images/homepage)

You can reproduce the problem by setting up two sites folders, adding an image to the node on the non-default site, then go back to the default site and try to view the node.

Comments

jrefano’s picture

Priority: Normal » Critical

I am still encountering this bug, here's an update that hopefully simplifies it a little.

My files folder is set in file system settings to sites/default/files.

I have a node with an imagefield. When my site is using the sites/default/settings.php file, everything works fine, the path renders like this (default Image handler):

sites/default/files/images/homepage/isl_home_color_block.jpg

when my site is using sites/domain.com/settings.php, the path renders as such:

sites/domain.com/files/sites/default/files/images/homepage/isl_home_color_block.jpg

Imagefield is appending the current site's path before the file path set in the file system settings, or perhaps its a CCK or Drupal bug?

Any idea what's happening here?

bredi’s picture

having same issue with multisite

quicksketch’s picture

Category: bug » support
Priority: Critical » Normal

I think you're misusing the multisite capabilities of Drupal. Drupal's support for multisite is intended to have multiple sites running off a single codebase, but every site gets a different database. If you're running two sites off the same database, you're doing something Drupal's multisite capability was not intended to do. You cannot expect FileField (or ImageField) to know where to find files if you've changed the installation root out from under it.

Take a look at the "files" table, and you'll see why this is. The path to all uploaded files is stored as "sites/default/files/myfile.png". So when you have the files directory set to "sites/default/files" (under admin/settings/file-system), Drupal is smart enough to know that sites/default/files/myfile.png is the file you want. However, if your files directory is set to "sites/mysite/files", and the files table has the path "sites/default/files/myfile.png", Drupal assumes that you must be referring to a file relative to "sites/default/files" so you end up with "sites/default/files/sites/mysite/files/myfile.png".

So this isn't a bug in FileField, you'd see the same thing if you were using Upload module or any other module for uploading files. Actually I'm not sure it's even a bug at all, I think that this just simply something not supported by Drupal. If using a multisite setup, every site should have its own files directory and database. The multisite functionality was never intended to share databases or files between sites.

quicksketch’s picture

Status: Active » Closed (fixed)
seanr’s picture

Title: Multi-site configuration results in incorrect file storage paths and/or imagefield display paths » Multi-site configuration results in incorrect file/imagefield display paths
Version: 6.x-3.0-alpha4 » 6.x-3.2
Category: support » bug
Status: Closed (fixed) » Active

This is still an issue and it needs to be fixed - it's not a misuse of multisite either. Here's a legit use case:

Main site: domain.com
SSL site: domain.ngphost.com (we use a shared certificate).

Thus, the directory setup for that looks like this:

dir: domain.com
link: domain.ngphost.com -> /[...]/sites/domain.com

We also use domain.ngphost.com for internal use while setting up the site before the domain is pointed at our servers. The result of this is that when we later go to launch the site, all imagefield images are broken and have to be manually edited in the database. Even then, however, if a user goes to a secure page on the site that displays an imafield in a block, that image will be broken on the secure page.

This use case is even in the Drupal handbook, BTW:

http://drupal.org/node/277

Please actually try to fix this rather than just assuming users are doing things incorrectly.

quicksketch’s picture

Category: bug » support
Status: Active » Closed (fixed)

Bug or not, it's not a problem with ImageField, it's a problem with core's storage of files. Because this can't be changed in Drupal 6, and because it IS fixed in Drupal 7, there's nothing more to be done.

4v4l0n42’s picture

Since there was no elegant way to solve this I found a workaround, maybe it can be helpful to some of you.

Assuming you are using apache:

RewriteCond %{HTTP_HOST} ^myothersite.net$
RewriteRule ^(.*)$ "http\:\/\/mysite.net/$1" [R=301,L]

then, create a symlink:

ln -s /path/to/mysite.net /path/to/myothersite.net

If you previously uploaded the files on myothersite.net, on the files table of your db, change the filepath from:

sites/myothersite.net/files/image.jpg

to:

sites/mysite.net/files/image.jpg

It can be this can be easily done in a batch by downloading the table in CSV format and replace all the occurrences with a text editor. To sum up, all the files that were added by the system will be fixed, those that were added manually (e.g: with wysiwyg editors) will work as well. The will point to:

/sites/myothersite.net/files/image.jpg

which is a symlink to:

/sites/mysite.net/files/image.jpg

It's not the most elegant solution, but it works, and it's the best I could find.

Hope this helps.

seanr’s picture

Project: ImageField » Drupal core
Version: 6.x-3.2 » 6.x-dev
Component: Code » file system
Priority: Normal » Major
Status: Closed (fixed) » Active

Since this was fixed in Drupal 7, is there any patch or other workaround that would fix the issue in #5 above for Drupal 6? We are having this problem with all of our multisites because they live at domain.ngphost.com until they're ready to go live, so files uploaded before that point end up broken after domain.com starts resolving. This really is proving to be a huge problem.

zwartschaap’s picture

The mod_rewrite solution posted by 4v4l0n42 is an option ofcourse. I opted for the mysql fix:

UPDATE xxx_files SET `filepath` = CONCAT('sites/mysite.example.com/files/',RIGHT(`filepath`, LENGTH(`filepath`)-yy))

Where xxx is your database prefix (see settings.php for your site), if none used, simply use `files` as table name.
And yy is the count of the erronous path, for instance 'sites/default/files/' is 20 chars.

So this update query changes
sites/default/files/my_picture.jpg
to
sites/mysite.example.com/files/my_picture.jpg

This does not fix the default picture unfortunately. Re-upload your default pic and that's fixed as well.

joachim’s picture

This works fine for me on D6, without hacking .htaccess.

The trick is to go to the file system settings and save the settings -- otherwise Drupal guesses this based on your site path, and hence depending on which site you're on will go to two different image paths.

charos’s picture

I think a cleaner solution is:
UPDATE `files` SET `filepath` = REPLACE(`filepath`, "sites/default/files/", "")
Courtesy of OpenSpring

cweagans’s picture

Priority: Major » Normal

Support requests are never major or critical.

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.