Closed (fixed)
Project:
ImageField
Version:
6.x-3.7
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
9 Sep 2010 at 15:22 UTC
Updated:
30 Apr 2013 at 17:34 UTC
1. CCK version: 6.x-2.8
2. imagefield version: 6.x-3.7
I created an image field for a custom content type, then create content > upload image.
I am having an issues with these IMAGES in Drupal pages. The problem is, they are being referenced as ABSOLUTE URL’s instead of RELATIVE URL’s.
For example from firebug:
<img class="imagefield imagefield-field_emblem" width="69" height="58" alt="" src="http://mysite.com/sites/default/files/Menominee_sm_0.png?1283886420"/>
As you can see, this is ABSOLUTE. I need to figure out how to make Drupal generate RELATIVE URLs. In other words, we need the page to look like this:
<img class="imagefield imagefield-field_emblem" width="69" height="58" alt="" src="/sites/default/files/Menominee_sm_0.png?1283886420"/>
Comments
Comment #1
quicksketchI'm not sure why it's imperative to make them relative instead of absolute, but you can do this by overriding theme_imagefield_image() for ImageField images and theme_imagecache() if using ImageCache.
Comment #2
mitchelljj commentedI *believe* I have fixed this … it’s working locally (as in, I’m getting relative URLS for uploaded images now). I’d like to know if changing the below will break anything else within Drupal.
Here’s what I did:
In “file.inc” (in includes folder), I took the argument for creating paths for PRIVATE uploads and replaced the argument for creating PUBLIC uploads with the same argument:
WAS:
switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
case FILE_DOWNLOADS_PUBLIC:
return $GLOBALS['base_url'] .'/'. file_directory_path() .'/'. str_replace('\\', '/', $path);
case FILE_DOWNLOADS_PRIVATE:
return url('system/files/'. $path, array('absolute' => FALSE));
}
}
NOW IS:
switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
case FILE_DOWNLOADS_PUBLIC:
return url('system/files/'. $path, array('absolute' => FALSE));
case FILE_DOWNLOADS_PRIVATE:
return url('system/files/'. $path, array('absolute' => FALSE));
}
}
Thus far nothing has broken – I’ve uploaded new images, created new content types and added image fields and uploaded new content. In firebug I’m getting back relative paths.
Comment #3
quicksketchI don't think hacking file.inc is a good way to go, as you'll need to remember to modify those files every time you update Drupal core for security updates. I'd really suggest theming as the way to fix this problem, which would keep the changes in your theme instead of modifying Drupal core.
Comment #4
quicksketchComment #5
PMorris commentedIf you just want to change imagefield you override it it template.php which is the recommended way.
all i changed was the line with "$url = file_create_url($path) . $query_string;" to " $url = $path . $query_string;" to get rid of the http://
I didn't test this extensively so beware. But it appears to work with a quick test with just an imagefield's path. garlandsub was the name of my test subtheme so change that to whatever theme name you have and put the code in template.php