After installing FileField 5.x-2.3-rc2, creating an ico directory and uploading several __.png files I still didn't see any icons.

Looking into the code of filefield.module (716-721) I found:

  $icon = '';
  $iconpath = base_path() .'/'. drupal_get_path('module','filefield') .'/ico/'. $ext .'.png';
  if (file_exists($iconpath)) {
    $icon = '<img class="field-icon-'. $ext .'" src="'. $imagepath .'" />';
  }
  return '<div class="filefield-icon field-icon-'. $ext .'">'. $icon .'</div>';

The trouble seems to be that $imagepath isn't defined (it seems to be $iconpath), there is a .'/'. too many and the "file_exists" can be problematic on a safe_mode PHP install.

I could make the icons work again by replacing the code above by the following:

  $icon = '';
  $iconpath = base_path() . drupal_get_path('module','filefield') .'/ico/'. $ext .'.png';
  if (!$size=@getimagesize($iconpath)) {
    $icon = '<img class="field-icon-'. $ext .'" src="'. $iconpath .'" />';
  }
  return '<div class="filefield-icon field-icon-'. $ext .'">'. $icon .'</div>';

In order be able to see the icons I also had to remove the div.filefield-icon definition from the filefield.css.

Now the icons are visible again while editing nodes and pasting the code from #196957: Add icons to default filefield formatters. into your template.php will make the icons show up while viewing nodes as well.

CommentFileSizeAuthor
#4 filefield.icon_.patch.txt705 bytesrobin van emden

Comments

jpetso’s picture

Status: Active » Needs work

It doesn't hurt to have a '/' too many, but it hurts when it's missing. I believe I inserted the slash in response to a bug report, because we can't rely on base_path() ending with a slash or drupal_get_path() starting with one.

Other than that, the change seems sensible to me. Please post the change (without slash removal) as a patch file, plus I'd like to know if dopry is ok with getimagesize().

robin van emden’s picture

Will post a patch file tomorrow, thank you for your quick reply! As a matter of fact I did have some trouble with a double slash at the start of the $iconpath string on a windows testing server.

I thought this might be because of the default behavior of file_exists (see http://us.php.net/file_exists):

On windows, use //computername/share/filename or \\computername\share\filename to check files on network shares.

If the getimagesize() solution is decided to be ok that might also solve this particular issue?

jpetso’s picture

Bah, those frickin' edge cases. In that case, I'd like to think that an rtrim(base_path()) should be sufficient for both the Windows network syntax and the case where base_path() doesn't return a trailing slash. Could you try if that works for you?

robin van emden’s picture

StatusFileSize
new705 bytes

Patch, haven't had time yet to test rtrim(base_path()), so for now it's based on my original code.

dopry’s picture

Status: Needs work » Fixed

This should be fixed in the latest 5.x-2.x dev branch.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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