我有3个文件
- upload.html//在服务器上传图片
- check_image.php
- filter.php//它在图像上创建一些过滤器,并返回check_image.php//稍后调用"filter.php
我有问题预览过滤后的图像输出一个图像没有出现在屏幕上。当我尝试重新加载图像时,我会收到以下消息:图像无法显示,因为它包含错误。我该如何解决这个问题?我的filter.php代码是:
<?php
. . .
if (isset($_GET['id']) && ctype_digit($_GET['id'])
&& file_exists($dir . '/' . $_GET['id'] . '.jpg')
) {
$image=imagecreatefromjpeg($dir . '/' . $_GET['id'] . '.jpg');
} else {
die('Invalid image specified!');
}
//apply the filter
$effect = (isset($_GET['e'])) ? $_GET['e'] : -1;
switch($effect) {
case IMG_FILTER_NEGATE:
. . .
}
//show the image
header('Content-Type: image/jpeg');
imagejpeg($image, '', 100);
?>
我认为这个问题是由于header()函数引起的,请帮助
您的页眉确实有一个轻微的拼写错误;将其更改为:
header("Content-Type:image/jpeg"); //note the no space after the colon.
header("Cache-Control:max-age=17280000, public"); //so as to enable caching - in most cases you do want this.
还要确保在header()之前没有任何输出,否则它将失败。
(但如果没有完整的代码,我当然无法测试它——我知道我刚刚提供的代码适用于我的用例。)HTH