运行脚本时出现以下错误
php cannot be displayed because it contains errors
脚本,获取文件,调整大小,将其输出到屏幕和文件。
url_example:localhost/testimage.php?img=img_592_121_200.jpg
我已阅读了大多数帖子并尝试过提出的解决方案。全部失败
该文件不会输出到屏幕/浏览器,但可以保存到文件中。
这是代码,我剥离了所有空白区域和空行。并在脚本中对文件名进行了硬编码
**我开始怀疑这是我的设置,但我不确定如何/从哪里开始寻找
编辑:简化为仅输出到屏幕
testimage.php
<?php
//session_start();
//ob_start();
ini_set("display_errors", "1");
error_reporting(E_ALL);
Header('Content-type:image/jpeg');
//$cacheFile="mypicXXX.jpg";
//$cache_dir="cache/1/592/";
$img_dir="webspace/1/592/";
$img="img_592_121.jpg";
$id="$img_dir$img";
$src=imagecreatefromjpeg($id);
$new_width=200;
$new_height=77;
$width=600;
$height=1001;
$w_src=600;
$h_src=1001;
$img=imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($img,$src,0,0,0,0,$new_width,$new_height,$w_src,$h_src);
imagejpeg($img,NULL,45);
//$cacheFile=$cache_dir.$cacheFile;
//imagejpeg($img,$cacheFile,45);
imagedestroy($src);
imagedestroy($img);
//ob_end_flush();
?>
答案 0 :(得分:1)
固定。修复(至少对我来说)是将文件保存为“UTF-8 - NO NOM”。之前我把它作为“UTF-8”
这整个文件格式让我迷失了,我需要在其中一天阅读
感谢所有帮助!!!
答案 1 :(得分:0)
您是否检查过标头之前没有发送输出? 你可以尝试几件事:
更新 您确定检查了指向的文件是否存在/或路径是否有效? 这适用于我的localhost,运行默认的xamp安装(PHP3.5.1)
ini_set("display_errors", "1");
error_reporting(E_ALL);
Header('Content-type:image/jpeg');
//$cacheFile="mypicXXX.jpg";
//$cache_dir="cache/1/592/";
$img_dir="webspace/1/592/";
$img="test.jpg";
$src=imagecreatefromjpeg($img);
$new_width=200;
$new_height=77;
$width=600;
$height=1001;
$w_src=600;
$h_src=1001;
$img=imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($img,$src,0,0,0,0,$new_width,$new_height,$w_src,$h_src);
imagejpeg($img,NULL,45);
//$cacheFile=$cache_dir.$cacheFile;
//imagejpeg($img,$cacheFile,45);
imagedestroy($src);
imagedestroy($img);