厚盒中的图像窗口显示奇怪的字符
我在 ubuntu 上的 ubercart/drupal 6 上使用厚盒。问题是我将站点从 Windows 计算机移至 ubuntu。路径和权限的所有问题均已排序,并且站点运行良好。 我现在遇到的唯一问题是当我单击产品图像时,thickbox 应该显示预览弹出窗口。相反,它在弹出窗口中显示奇怪的字符。这些字符的复制/粘贴:
����JFIF�,,�����Exif��MM� ��������������������(������1��������2���������� ......我......4NIKON CORPORATION.NIKON D70s......,......,......Adobe Photoshop 7.0�2008:08:21 17:13:50 ���%�������������������“�����������0221������������ ��������������֒���������������������������������� ���������������,������90��������90��������90�������� �0100�������������������������������������������� ��������“������������������������������������ ���������������������������������������������� �������������� ��X������� 2008:08:19 15:40:17��2008:08:19 15:40:17���� ������������+���� ������ ASCII���� ������������������������ ����������(��������������������W������H������H��� ����JFIF��H�H�����Adobe_CM����Adobe�d�������������7"������?? �3�!1AQa
。文件/。甚至缩略图也会生成。另外,右键单击缩略图并在新选项卡中打开可以正确显示整个图像。
此外,Thickbox 会将图像的 ajax GET 请求发送到如下所示的 URL:
http://127.0.0.1/elegancia/?q=system/files/imagecache/product_full/image_1.jpg&random=1299550719133
将 Firebug 中的相同请求复制粘贴到新的浏览器选项卡中,成功打开图像。
从 firebug 中,这些是 ajax 请求的请求响应标头:
Response Headers
view source
Date Tue, 08 Mar 2011 02:18:39 GMT
Server Apache/2.2.16 (Ubuntu)
X-Powered-By PHP/5.3.3-1ubuntu9.3
Expires Tue, 22 Mar 2011 02:18:39 GMT
Last-Modified Tue, 08 Mar 2011 01:21:47 GMT
Cache-Control max-age=1209600, private, must-revalidate
Content-Length 111831
Etag "4dfe0f3d345781ac89aae5c2a10361ad"
Keep-Alive timeout=15, max=92
Connection Keep-Alive
Content-Type image/jpeg
Request Headers
view source
Host 127.0.0.1
User-Agent Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.2.15) Gecko/20110303 Ubuntu/10.10 (maverick) Firefox/3.6.15
Accept text/html, */*
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://127.0.0.1/elegancia/
Cookie SESS7a3e11dd748683d65ee6f3c6a918aa02=bijhrr4tl66t42majfs3702a06; has_js=1
I am using thickbox on ubercart/drupal 6 on ubuntu. The problem is I moved the site from a windows machine to ubuntu. All problems with paths and permissions sorted and site is working well.
The only problem I'm having now is when I click on a product image, thickbox is supposed to show a preview pop up. Instead, it shows weird characters in the pop up window. A copy/paste of those characters:
�����JFIF�,,�����Exif��MM����� ���������������������������������������(�������1��������2����������������i����������4NIKON CORPORATION�NIKON D70s���,�����,���Adobe Photoshop 7.0�2008:08:21 17:13:50���%�������������������"�������������0221���������������������������֒� �����ޒ������������������������ �������� ����������,�������90��������90��������90��������0100��������������������������������������������������������"���������������������������������������E������������������������������ ��������� ����������������������� ��X������� 2008:08:19 15:40:17�2008:08:19 15:40:17�����������������+��� ������ ASCII��� ���������������������������������(�������������������� W�������H������H��������JFIF��H�H�����Adobe_CM����Adobe�d��������� ������7"�������?���������� ��������� �3�!1AQa . . . . . . and a lot more similar chars
The images are uploaded properly and I can see them under sites/default/files/. Even the thumbnails are generated. These thumbnails appear on the site as well. Also right clicking a thumbnail and open in new tab shows me the whole image properly.
Also, Thickbox sends an ajax GET request for the image to a URL that looks something like this:
http://127.0.0.1/elegancia/?q=system/files/imagecache/product_full/image_1.jpg&random=1299550719133
Copy pasting the same request from firebug into a new browser tab opens the image successfully.
From firebug, these are the request response headers for the ajax request:
Response Headers
view source
Date Tue, 08 Mar 2011 02:18:39 GMT
Server Apache/2.2.16 (Ubuntu)
X-Powered-By PHP/5.3.3-1ubuntu9.3
Expires Tue, 22 Mar 2011 02:18:39 GMT
Last-Modified Tue, 08 Mar 2011 01:21:47 GMT
Cache-Control max-age=1209600, private, must-revalidate
Content-Length 111831
Etag "4dfe0f3d345781ac89aae5c2a10361ad"
Keep-Alive timeout=15, max=92
Connection Keep-Alive
Content-Type image/jpeg
Request Headers
view source
Host 127.0.0.1
User-Agent Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.2.15) Gecko/20110303 Ubuntu/10.10 (maverick) Firefox/3.6.15
Accept text/html, */*
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://127.0.0.1/elegancia/
Cookie SESS7a3e11dd748683d65ee6f3c6a918aa02=bijhrr4tl66t42majfs3702a06; has_js=1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来这是一个厚盒(Javascript)问题。 PHP 和 Apache 在使用 mime 识别图像时工作得很好。
如果图像 URL 中有参数,例如。
(http://127.0.0.1/elegancia/?q=system/files/imagecache/product_full/image_1.jpg&random=1299550719133)
- 由于厚盒图像识别算法,导致厚盒显示无意义字符。
不以图像扩展名结尾的 URL 会使厚盒 JavaScript 将图像视为另一种非图像的 MIME 类型。
要解决此问题,需要修改 /modules/thickbox/thinkbox.js 的第 53 行,将“ || urlType == '/preview' ” 添加到选项列表中,以使 Thickbox.js 坚信其核心是Drupal 编码的图像链接实际上是图像而不是冒名顶替者。
假设您的图像大小是“预览”,请将第 53 行从: 更改
为:
另外,将第 50 行修改为:(
用“/preview”替换“/thumbnail”、“/quarter”或您将图像模块配置为的任何内容创建(并命名)各种尺寸。
Looks like it was a thickbox (Javascript) issue. PHP and Apache work fine when it comes to recognizing the image using mime.
If there are arguments in the image URL, eg.
(http://127.0.0.1/elegancia/?q=system/files/imagecache/product_full/image_1.jpg&random=1299550719133)
- causes Thickbox to show nonsense characters instead due to thickbox image recognition algorithm.
URLs not ending with an image extension makes the thickbox javascript to treat the image like another mime type that is not an image.
To work around, one needs to modify line 53 of /modules/thickbox/thinkbox.js, by adding " || urlType == '/preview' " to the list of choices in order to make thickbox.js believe in its heart that a Drupal-encoded image link is in fact an image and not an imposter.
Assuming your image size is "preview," change line 53 from:
to this:
Also, modify line 50 to this:
(substitute "/preview" for "/thumbnail," "/quarter," or whatever you configured your image module to create (and name) various sizes.
我发现的另一个解决方案是在 URL 中添加 path_info 来指定图像类型。例如,我以前的 URL 是:
/image.php?foo=bar
我将其更改为:
/image.php/image.gif?foo=bar
请注意,如果您使用的是 Apache 等网络服务器,默认情况下它会限制使用 path_info 时,您可能需要使用受影响路径的 AcceptPathInfo 指令将其打开。
与更改 Thickbox 源代码相比,我更喜欢此解决方案,因为更改可能被更新版本替换的模块意味着可能会丢失修复,而更改 path_info 应在任何升级中继续发挥作用。
Another solution which I've found is to add a path_info addition to the URL to specify the image-type. For example, my URL previously was:
/image.php?foo=bar
I changed it to:
/image.php/image.gif?foo=bar
Note that if you're using a webserver such as Apache, which by default restricts the use of path_info, you may need to turn it on with the AcceptPathInfo directive for the affected path.
I prefer this solution to altering the Thickbox source, because altering modules which may get replaced with updated versions means a possible loss of fixes, whereas altering the path_info should continue to function with any upgrades.
浏览器将文件呈现为文本,而它本应将其视为 JPEG 图像。您需要发送“Content-Type: image/jpeg”标头来告诉浏览器如何呈现内容。检查您的网络服务器配置。
对于 Apache,您的 httpd.conf 文件应包含如下行:
然后,在 /etc/mime.types 中:
这全部适用于由 Web 服务器直接提供服务的文件。如果您可以在浏览器中输入 URL 并看到图像,那么这一切都不是问题。
如果文件由脚本提供,那么您需要确保标头由脚本发送。在 PHP 中:
The browser is rendering the file as text, when it should treat it as a JPEG image. You need to send the 'Content-Type: image/jpeg' header to tell the browser how to render the content. Check your web server configuration.
For Apache, your httpd.conf file should have lines like this:
And then, in /etc/mime.types:
This all applies to files which are served by the web server directly. If you can enter the URL in a browser and see the image, then none of this is a problem.
If the files are served by a script, then you need to make sure the header is sent by the script. In PHP: