When I want to add an image with the [Select image] link, the page is only reloaded and IMCE not opens.
The problem seems to be on line 604 and 608 of imceimage.module

$remove_href = "javascript:imceImage.remove('$delta-$field_id')";
//$remove_link = '<a class="imceimage-remove" href="' . $href . '">' . t('Remove') . '</a>';  -> pb with $href -> replaced by :
$remove_link = '<a class="imceimage-remove" href="' . $remove_href . '">' . t('Remove') . '</a>';

  $imce_url = url('imce');
  $select_href = "javascript:imceImage.open('$imce_url', '$delta-$field_id')";
 //$select_link = '<a href="' . $href . '" class="imceimage-add">' . t('Select Image') . '</a>'; -> pb with $href -> replaced by :
  $select_link = '<a href="' . $select_href . '" class="imceimage-add">' . t('Select Image') . '</a>';

Comments

lucuhb’s picture

When URL of the image contains special characters, the file is checked as invalid image.

To resolve this problem, the url should be decoded before checking. A solution to make this, in _imceimage_image_to_filepath function :

/**
 * Helper function to find out file location from a URL.
 */
function _imceimage_image_to_filepath($url) {
  $doc_root = $_SERVER['DOCUMENT_ROOT'];
  $file_path = $doc_root .'/'. $url;
//return $file_path; -> decode url before return it :
  return rawurldecode($file_path);
}

This works with files with no special characters too.

donquixote’s picture

Thanks for the report.
6.x-2.0-alpha2 contains an attempted fix.

<?php
  $imce_url = url('imce');
  $select_href = check_plain("javascript:imceImage.open('$imce_url', '$delta-$field_id')");
  $select_link = '<a href="' . $select_href . '" class="imceimage-add">' . t('Select Image') . '</a>';
?>

I wonder, do we need to further escape the $imce_url, before it goes into the $select_href? addslashes?

lucuhb’s picture

I don't think it is necessary, it works for me