简体   繁体   English

Google Chrome浏览器“无法加载资源”

[英]Google Chrome “Failed to load resource”

I am using a watermarking system to protect all my photos on my page: 我正在使用水印系统来保护我页面上的所有照片:

<?php
$imagesource = $_SERVER['DOCUMENT_ROOT']."**path**".$_GET['path'];
if (!file_exists($imagesource)) die();
$filetype = strtolower(substr($imagesource,strlen($imagesource)-4,4));
if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); 
if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); 
if($filetype == ".png") $image = @imagecreatefrompng($imagesource); 
if (empty($image)) die();
$watermark = @imagecreatefrompng('watermark_'.(imagesx($image) <= 1100 ? "port" : "lans").'.png');
$imagewidth = imagesx($image);
$imageheight = imagesy($image); 
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth)/2);
$startheight = (($imageheight - $watermarkheight)/2);
imagecopy($image, $watermark,  $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
header("Content-type: image/jpeg");
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>

This works fine, however when I load this page in Google Chrome the images pre-load and display but as soon as they render Chrome says "Failed to load resource". 效果很好,但是当我在Google Chrome浏览器中加载此页面时,图像会预先加载并显示,但是一旦渲染,Chrome就会显示“无法加载资源”。 Which is strange because if you failed to load it why were you displaying it then? 奇怪的是,如果加载失败,为什么要显示它呢?

Anyways I cannot replicate this issue on any other browser. 无论如何,我无法在任何其他浏览器上复制此问题。 Which is again strange, this tells me that there is nothing wrong with the script. 再次奇怪的是,这告诉我脚本没有错。

I have been noticing the smaller the images I have the more display correctly, but what good is 2 out of 19 images loading!! 我注意到较小的图像可以正确显示,但是加载19张图像中的2张有什么用呢!

Now this does not happen when i display the images normally (ie without the watermarking script. through "<"img"><"/img">" tags) 现在,当我正常显示图像时(即没有水印脚本。通过“ <“ img”> <“ / img”>“标签),这不会发生

But on another website I have there is no watermarking script, but they still do not load. 但是在另一个网站上,我没有水印脚本,但是它们仍然无法加载。

Another question I have is; 我的另一个问题是;

I have to use copyright and .htaccess protection on the original files because of the laws governing my website contract... Anyway so the user cannot access the image source files directly. 由于管辖我的网站合同的法律,我必须对原始文件使用版权和.htaccess保护。无论如何,这样用户就无法直接访问图像源文件。 Could these errors be a result of this? 这些错误可能是由此导致的吗? But then again why would some display and others not, and in the same way why is it only Google Chrome that has this issue? 但是又为什么不显示某些内容,而为什么不显示?以同样的方式,为什么只有Google Chrome才出现此问题呢?

Your thoughts would be appriciated. 您的想法会被应用。

PS this is my browser info: PS这是我的浏览器信息:

Google Chrome   19.0.1084.56 (Official Build 140965) m
OS  Windows
WebKit  536.5 (@119244)
JavaScript  V8 3.9.24.29
Flash   11,3,300,257
User Agent  Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5

Visual Example: 可视示例:

载入中

已加载

Appears to be a bug in chrome. 似乎是Chrome中的错误。 Been driving me crazy ended up coming up with a "fix" using base64. 一直让我发疯,最终导致使用base64进行“修复”。 Leave your watermarking script exactly the same and go into the script that is outputting the images. 保持水印脚本完全相同,然后进入输出图像的脚本。

function base64_encode_image ($imagefile) {
      $filename=htmlentities($imagefile);
      $filetype = pathinfo($filename, PATHINFO_EXTENSION);
      $imgbinary = file_get_contents($filename);
      return 'data:image/' . $filetype . ';base64,' . base64_encode($imgbinary);
}

$string=base64_encode_image("http://www.domain.com.au/watermark.php?imagesrc=image1.jpg");

$imgList.="<img src=\"$string\" title=\"\">";

Probably the problem is due because you don't give back the Content-Lentgh. 可能是由于您不退还Content-Lentgh而引起的。

You have to replace the line imagejpeg($image); 您必须替换行imagejpeg($image); with the following code: 使用以下代码:

    imagejpeg($image, 'php://memory/temp.jpeg'); 
    header("Content-Length: " . filesize('php://memory/temp.jpeg'));
    $fp = fopen("php://temp/temp.jpeg", 'r');
    echo stream_get_contents($fp);

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

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