image upload works but I get no previews and wrong image link. images are being uploaded to sites/* but inserted links and preview point to /u*/

i am using imce with ckeditor

#45 846136_committed.patch1.22 KBdnotes
#33 set_file-url.patch630 bytesStevenWill
Members fund testing for the Drupal project. Drupal Association Learn more


tanc’s picture

Same issue noted here. Using 6.x-2.x-dev with TinyMCE and IMCE wysiwyg bridge. Url returned by IMCE is incorrect and does not have the full files directory path (e.g. missing sites/default/files/)

priyodevil’s picture

any ideas on a fix??

rjacobs’s picture

I noticed a similar (but not exact) problem with 2.0-beta3. Uploads worked but the images were always broken in the browser. It turns out this was because IMCE was trying to access them via "s/default/files/"
instead of "sites/default/files/" (notice that the "sites" part was just cut-off).

I was having this problem on a local (MAMP) server that was running under the domain "localhost:8888" (non-standard port). When I moved the same install (mirrored code and database) to a public hosting environment (without the non-standard port) everything worked fine.

I know this could easily be because of different versions (php, MySQL, etc.) between server environments, but because the issue was path-related, my best guess (in my situation) was that is had something to do with the port.

Again, this could be a completely different problem, but I wanted to make a note here in case it helps anyone. Regardless, if IMCE could in fact be confused by a non-standard port, this would certainly seem like a bug.


priyodevil’s picture

I am running this on production server. No port issues here. Problem persists.

priyodevil’s picture

Any ideas anybody? In desperate need of a fix.

ufku’s picture

As rjacobs stated this was a port issue and fixed in the dev branch.
Run update.php, clear the caches.

priyodevil’s picture

Done. Problem still persists.

ufku’s picture

Look at the page source and find out what IMCE defines as the base file path. Look for something like "furl": ""

shopdogg’s picture

I have the same problem. Imce defines the base file path like this "furl":"\/"

ufku’s picture

What is your "File system path" defined at admin/settings/file-system?

shopdogg’s picture

"File system path": sites/default/files

bonked’s picture

Had the same issue after upgrade last night.

Changing line 710 of inc/ from:

$imce['furl'] = file_create_url('');


$imce['furl'] = file_directory_path() . file_create_url('');

Seems to have fixed it for us. I don't normally like to hack away like that - but I'm kind of swamped, will try to make a proper patch this evening.

priyodevil’s picture

$imce['furl'] = file_directory_path() . file_create_url('');

but inserted image still points to wrong location

the fix that worked for me is

$imce['furl'] = "/" . file_directory_path() . file_create_url('');

on my dev version of imce this is at line 720

tanc’s picture

You'd probably want:
$imce['furl'] = base_path() . file_directory_path() . file_create_url('');
Base path should always be used as it will point to the root directory of the Drupal install.

ufku’s picture

function file_create_url($path) {
  // Strip file_directory_path from $path. We only include relative paths in urls.
  if (strpos($path, file_directory_path() .'/') === 0) {
    $path = trim(substr($path, strlen(file_directory_path())), '\\/');
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
      return $GLOBALS['base_url'] .'/'. file_directory_path() .'/'. str_replace('\\', '/', $path);
      return url('system/files/'. $path, array('absolute' => TRUE));

How can this function return / for file_create_url('')?

Can anybody test the result of file_create_url('')?

shopdogg’s picture

I have less experience, but if you can tell me how to test, I will do it.

ufku’s picture

Enable PHP input format and go to node/add/page.
Preview the content(no need to save)

print file_create_url('');

Also try it with some real filepaths, ex: file_create_url('sites/default/files/foo.jpg')

shopdogg’s picture

I tried that without and with different filepaths and the preview returned every time
Parse error: syntax error, unexpected T_FUNCTION in /www/htdocs/w00cd699/includes/ : eval()'d code on line 2

ufku’s picture

This is the correct one

print file_create_url('');
shopdogg’s picture

<?php print file_create_url(''); ?> returns /
<?php print file_create_url('sites/default/files/example.jpg'); ?> returns

ufku’s picture

Check the file_create_url function in includes/
Is it the same as #15?

steinmb’s picture

Had the same problem with D6.17, MAMP and latest stable IMCE. It kept inserting/using in the image browser —the path s/[filepath] but updating to the last dev. release fixed this/my issue (@ufku thanx!)

Make sure to delete the old imce dir before installing the new release to make sure you do not have old code/files laying around and to a "drush cc all" to clean out your caches.

technicka’s picture

#14 is what worked for me. Before hand my URLs were missing the "sites/sitename/files". Also this must have something to do with ports as mentioned above, as when I was on my local machine this worked fine and then transferred to web host and it stopped working.

Also, was running the IMCE dev version and this didn't solve anything despite running update.php and clearing cache.

roneill’s picture

#14 Worked for me as well. It is now line 721 in inc/ A fix to this would be excellent.

mani.atico’s picture

Status: Active » Reviewed & tested by the community

#14 worked for me.

ufku’s picture

Status: Reviewed & tested by the community » Active

Obviously, this issue is specific to a minority. The solution in #14 will break the rest.
You have to find what you have in common and identify the source of the problem.
Please see my previous comments.

sime’s picture

sime’s picture

If you are brave (and it's not a complete fix) you might maintain a patch on Pressflow until it's fixed. I'll just post a hint here, because I don't claim that this solution is a fix but may help those in a bind.

Just before "// Shipped files." in file_create_url() in add this:

  // Tempory modification to fix pressflow's inability to return a file
  // url for $path arguments relative to the files directory.
  // @see
  // @see
  $full_relative_path = file_directory_path() . '/' . trim($path, '/');
  if (file_exists($full_relative_path)) {
    return base_path() . $full_relative_path;
momendo’s picture

#14 worked for me. FYI, I'm not using Pressflow at all.

momendo’s picture

Version: 6.x-2.x-dev » 6.x-2.0-rc1
Category: support » bug


jleinenbach’s picture


ufku’s picture

Category: bug » support

If you mark an issue as a bug, please write down the steps to reproduce it. So, anyone can reproduce it.
And please read all the comments and try to help debugging if you think it's a bug.
You can start by a clean drupal install with only the buggy module enabled and test.

StevenWill’s picture

630 bytes

The following patch changes "$imce['furl']" to use "file_directory_path()" instead of "file_create_url('')". This method is compatible with the drupal file API and works for both Drupal and Pressflow. It also makes more since to call the directory when dealing with files. Please test so we can get this submitted.

TravisCarden’s picture


chadd’s picture


ufku’s picture

Version: 6.x-2.0-rc1 » 6.x-2.x-dev
Status: Active » Fixed

This is fixed in 2.x-dev(2010-Aug-17)

chadd’s picture

you linked to August 16, 2010, is that the correct dev version that has this fix?

ufku’s picture

Development releases are built nightly. A commit is included in the following day's release.

chadd’s picture

current dev release fixed it for me.

kwhatcher’s picture

Confirm Dev release fixed issue

boran’s picture


I just upgrade to dev, and tried to insert an image.
The patch is now /sites/wingo/filesu9/connect1.png"
There is a "/" missing between "files" and "u9".

I'm using pressflow.

The upgrade changes the follwoing lines for me:

@@ -718,7 +718,8 @@ function imce_initiate_profile($user) {
       $imce['url'] = url($_GET['q']);
       $imce['clean'] = variable_get('clean_url', 0) == 1;
       $imce['absurls'] = variable_get('imce_settings_absurls', 0) == 1;
-      $imce['furl'] = file_create_url('');
+      $private = variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE;
+      $imce['furl'] = $private ? url('system/files') : base_path() . file_directory_path();

Changing the relevant line to:

$imce['furl'] = $private ? url('system/files') : base_path() . file_directory_path() .'/';

fixed it for me. Could this be commited too please?

ufku’s picture

imce.js was also patched. clear the caches and make sure the new one loads.

boran’s picture

Yes, you have a point, on flushing caches it was no longer necessary to add the "/".

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dnotes’s picture

1.22 KB

Just adding a patch from for my drush make files - I don't wanna use the dev version for makefiles, so until a new RC comes out I'm going to patch RC1 with this. Thanks for the fix.