【发布时间】:2013-11-11 06:58:56
【问题描述】:
所以,大家快速提问...我有一个 PHP 文件,它可以生成一个编辑过的图像。该文件如下所示。它从服务器抓取图像并按照特定规范对其进行裁剪。
<?php
header("Content-Type: image/jpg");
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
$src = getcwd()."/".$_GET["img"].".jpg";
$screenw = $_GET["sw"];
$screenh = $_GET["sh"];
$jpeg_quality = 100;
$w = $screenw;
$h = 428;
$targ_w = $w;
$targ_h = $h;
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
$x = 1000 - floor($screenw / 2);
$y = 1000 - floor(428 / 2);
imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $targ_w, $targ_h, $w, $h);
imagejpeg($dst_r, null, 100);
exit;
?>
该文件在我的本地 MAMP 服务器上运行良好。但是,当我将它上传到 000webhost 时,我立即得到了一个
图片 image1 包含错误,无法显示
消息。而且,经过一些测试,我认为我的标题是它的原因。如果我卷曲它,实时站点的结果是:
Date: Mon, 11 Nov 2013 06:47:40 GMT
Server: Apache
X-Powered-By: PHP/5.2.17
Connection: close
Content-Type: image/jpeg
和本地主机:
Date: Mon, 11 Nov 2013 06:52:20 GMT
Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8y DAV/2 PHP/5.4.10
X-Powered-By: PHP/5.4.10
Content-Type: image/jpeg
我看到在实时站点上发送标头之前连接关闭,因此引发错误...为什么会发生这种情况?我的代码有问题吗?这可以在PHP中解决吗?请告诉我。提前谢谢大家。
【问题讨论】:
-
向我们展示您的完整图片交付代码。
-
我刚刚添加了其余代码作为帖子编辑
-
在发送标题和内容之前尝试
ob_end_clean()。error_reporting(E_ALL);没有报任何我认为的错误?
标签: php curl header http-headers