简体   繁体   English

厚框中的图像窗口显示奇怪的字符

[英]Image window in thickbox shows weird characters

I am using thickbox on ubercart/drupal 6 on ubuntu. 我在Ubuntu上的ubercart / drupal 6上使用thickbox。 The problem is I moved the site from a windows machine to ubuntu. 问题是我将该站点从Windows计算机移到了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. 我现在遇到的唯一问题是,当我单击产品图片时,thickbox应该会显示预览弹出窗口。 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 ( 1 2 4NIKONCORPORATION NIKOND70s , , AdobePhotoshop7.0 2008:08:21 17:13:50 % ''。 ֒  , 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 E X X: 2008:08:19 15:40:17 2008:08:19 15:40:17 ASCII ( H JFIF H H Adobe_CM Adobe d 7'' ? 3 !

The images are uploaded properly and I can see them under sites/default/files/. 图片已正确上传,我可以在site / 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: 另外,Thickbox将对图像的Ajax GET请求发送到看起来像这样的URL:

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. 将相同的请求从Firebug复制粘贴到新的浏览器选项卡中将成功打开图像。

From firebug, these are the request response headers for the ajax request: 从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

Looks like it was a thickbox (Javascript) issue. 看起来这是一个thickbox(Javascript)问题。 PHP and Apache work fine when it comes to recognizing the image using mime. 当使用mime识别图像时,PHP和Apache可以正常工作。

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. (http://127.0.0.1/elegancia/?q=system/files/imagecache/product_full/image_1.jpg&random=1299550719133)-由于thickbox图像识别算法,导致Thickbox显示无意义的字符。 URLs not ending with an image extension makes the thickbox javascript to treat the image like another mime type that is not an image. 不以图像扩展名结尾的URL使thickbox javascript将图像视为不是图像的另一种MIME类型。

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. 要变通,需要修改/modules/thickbox/thinkbox.js的第53行,方法是在选项列表中添加“ || urlType =='/ preview'”,以使thickbox.js相信它的核心Drupal编码的图像链接实际上是图像,而不是冒名顶替者。

Assuming your image size is "preview," change line 53 from: 假设您的图片大小为“预览”,请将第53行更改为:

if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp' ){//code to show images

to this: 对此:

if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp' || urlType == '/preview'){//code to show images

Also, modify line 50 to this: 另外,将第50行修改为:

var urlString = /\.jpg|\.jpeg|\.png|\.gif|\.bmp|\/preview/g;

(substitute "/preview" for "/thumbnail," "/quarter," or whatever you configured your image module to create (and name) various sizes. (用“ / preview”代替“ / thumbnail”,“ / quarter”,或配置了图像模块以创建(和命名)各种尺寸的任何东西。

Another solution which I've found is to add a path_info addition to the URL to specify the image-type. 我发现的另一种解决方案是在URL中添加path_info附加信息以指定图像类型。 For example, my URL previously was: 例如,我的URL以前是:

/image.php?foo=bar /image.php?foo=bar

I changed it to: 我将其更改为:

/image.php/image.gif?foo=bar /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. 请注意,如果您使用的是Apache之类的网络服务器,默认情况下会限制path_info的使用,则可能需要使用受影响路径的AcceptPathInfo指令将其打开。

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. 我更喜欢这种解决方案,而不是更改Thinbox源,因为更改可能被更新版本替换的模块意味着可能会丢失修复程序,而更改path_info应该在所有升级中继续起作用。

The browser is rendering the file as text, when it should treat it as a JPEG image. 当浏览器将其视为JPEG图像时,它会将文件呈现为文本。 You need to send the 'Content-Type: image/jpeg' header to tell the browser how to render the content. 您需要发送“ Content-Type:图片/ jpeg”标头,以告诉浏览器如何呈现内容。 Check your web server configuration. 检查您的Web服务器配置。

For Apache, your httpd.conf file should have lines like this: 对于Apache,您的httpd.conf文件应具有以下行:

LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule mime_module modules/mod_mime.so

...

TypesConfig /etc/mime.types

And then, in /etc/mime.types: 然后,在/etc/mime.types中:

image/jpeg          jpeg jpg jpe

This all applies to files which are served by the web server directly. 所有这些都适用于直接由Web服务器提供服务的文件。 If you can enter the URL in a browser and see the image, then none of this is a problem. 如果您可以在浏览器中输入URL并查看图像,那么这都不是问题。


If the files are served by a script, then you need to make sure the header is sent by the script. 如果文件是由脚本提供的,则需要确保标题是由脚本发送的。 In PHP: 在PHP中:

header('Content-type: image/jpeg');
echo file_get_contents($image_path);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM