Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当Firefox说“我怎么知道错误是什么?”;无法显示图像,因为它包含错误“;_Php_Google Chrome_Firefox_Asp.net Core - Fatal编程技术网

Php 当Firefox说“我怎么知道错误是什么?”;无法显示图像,因为它包含错误“;

Php 当Firefox说“我怎么知道错误是什么?”;无法显示图像,因为它包含错误“;,php,google-chrome,firefox,asp.net-core,Php,Google Chrome,Firefox,Asp.net Core,我有一个制作图像的PHP文件。我已经将PHP配置为在屏幕上报告错误。当我在Firefox23的php文件中运行该文件时,它返回图像无法显示,因为它包含错误 如何找出图像中的具体错误 额外信息以下是代码 <?php $tfont[] = 'cylburn-webfont.ttf'; $cryptinstall="./cryptographp.fct.php"; include $cryptinstall; error_reporting(E_ALL ^ E_NOTICE); sra

我有一个制作图像的PHP文件。我已经将PHP配置为在屏幕上报告错误。当我在Firefox23的php文件中运行该文件时,它返回
图像无法显示,因为它包含错误

如何找出图像中的具体错误

额外信息以下是代码

<?php

$tfont[] = 'cylburn-webfont.ttf'; 

$cryptinstall="./cryptographp.fct.php";
include $cryptinstall; 

error_reporting(E_ALL ^ E_NOTICE);
srand((double)microtime()*1000000); 

if ($_GET[$_GET['sn']]=="") unset ($_GET['sn']); 
session_start();

include('getcaptcha.php'); 
$question = getcaptcha();
$questionLen = strlen($question);
$cryptwidth  = 25 * $questionLen;

$cryptinstall2="./cryptographp.cfg.php";
include $cryptinstall; 

$cryptwidth=900;
$cryptheight=200;

// CrÈation du cryptogramme temporaire
$imgtmp = imagecreatetruecolor($cryptwidth,$cryptheight);
$blank  = imagecolorallocate($imgtmp,255,255,255);
$black   = imagecolorallocate($imgtmp,0,0,0);
imagefill($imgtmp,0,0,$blank);

$word ='';
$x = 10; 
$pair = rand(0,1);
$charnb = rand($charnbmin,$charnbmax);


for ($i=0;$i<= $questionLen;$i++) {            
     $tword[$i]['font'] =  $tfont[array_rand($tfont,1)];
     $tword[$i]['angle'] = (rand(1,2)==1)?rand(0,$charanglemax):rand(360-$charanglemax,360);

     $tword[$i]['element'] = str_split($question)[$i-1];

     $tword[$i]['size'] = rand($charsizemin,$charsizemax);
     $tword[$i]['y'] = ($charup?($cryptheight/2)+rand(0,($cryptheight/5)):($cryptheight/1.5));
     $word .=$tword[$i]['element'];

     $lafont="fonts/".$tword[$i]['font'];
     imagettftext($imgtmp,$tword[$i]['size'],$tword[$i]['angle'],$x,$tword[$i]['y'],$black,$lafont,$tword[$i]['element']);

     $x +=$charspace;
     } 

// Calculate horizontal racadrage temporary cryptogram
$xbegin=0;
$x=0;
while (($x<$cryptwidth)and(!$xbegin)) {
     $y=0;
     while (($y<$cryptheight)and(!$xbegin)) {
           if (imagecolorat($imgtmp,$x,$y) != $blank) $xbegin = $x;
           $y++;
           }
     $x++;
     } 

$xend=0;
$x=$cryptwidth-1;
while (($x>0)and(!$xend)) {
     $y=0;
     while (($y<$cryptheight)and(!$xend)) {
           if (imagecolorat($imgtmp,$x,$y) != $blank) $xend = $x;
           $y++;
           }
     $x--;
     } 

$xvariation = round(($cryptwidth/2)-(($xend-$xbegin)/2));
imagedestroy ($imgtmp);

// Create the final cryptogram
// Create the background
$img = imagecreatetruecolor($cryptwidth,$cryptheight); 

if ($bgimg and is_dir($bgimg)) {
                    $dh  = opendir($bgimg);
                    while (false !== ($filename = readdir($dh))) 
                          if(eregi(".[gif|jpg|png]$", $filename))  $files[] = $filename;
                    closedir($dh);
                    $bgimg = $bgimg.'/'.$files[array_rand($files,1)];
                    }
if ($bgimg) {
            list($getwidth, $getheight, $gettype, $getattr) = getimagesize($bgimg);
                $imgread = imagecreatefrompng($bgimg); break;
                imagecopyresized ($img, $imgread, 0,0,0,0,$cryptwidth,$cryptheight,$getwidth,$getheight);
                imagedestroy ($imgread);
            }
            else {
                 $bg = imagecolorallocate($img,$bgR,$bgG,$bgB);
                 imagefill($img,0,0,$bg);
                 if ($bgclear) imagecolortransparent($img,$bg);
                 }


function ecriture()
{
// CrÈation de l'Ècriture
global  $img, $ink, $charR, $charG, $charB, $charclear, $xvariation, $charnb, $charcolorrnd, $charcolorrndlevel, $tword, $charspace;
$ink = imagecolorallocatealpha($img,$charR,$charG,$charB,$charclear);

global $question;
global $questionLen;

$x = $xvariation;
for ($i=1;$i<$questionLen;$i++) {       

    if ($charcolorrnd){   // Choisit des couleurs au hasard
       $ok = false;
       do {
          $rndcolor = 0;
          switch ($charcolorrndlevel) {
                 case 1  : if ($rndcolor<200) 
                 $ok=true; break; // tres sombre
                 default : $ok=true;               
                 }
          } while (!$ok);

      $rndink = imagecolorallocatealpha($img,$rndR,$rndG,$rndB,$charclear);

    }  

    $lafont="fonts/".$tword[$i]['font'];
    imagettftext($img,$tword[$i]['size'],$tword[$i]['angle'],$x,$tword[$i]['y'],$charcolorrnd?$rndink:$ink,$lafont,$tword[$i]['element']);

    $x +=$charspace;
    } 
}


function noisecolor()
// Fonction permettant de dÈterminer la couleur du bruit et la forme du pinceau
 {
 global $img, $noisecolorchar, $ink, $bg, $brushsize;
 switch ($noisecolorchar) {
         case 1  : $noisecol=$ink; break;
         case 2  : $noisecol=$bg; break;
         case 3  : 
         default : $noisecol=imagecolorallocate ($img,0,0,0); break;               
         }
 if ($brushsize and $brushsize>1 and function_exists('imagesetbrush')) {
    $brush = imagecreatetruecolor($brushsize,$brushsize);
    imagefill($brush,0,0,$noisecol);
    imagesetbrush($img,$brush);
    $noisecol=IMG_COLOR_BRUSHED;
    }
 return $noisecol;    
}


function bruit()
//Adding noise: points, lines and circles random
{
global $noisepxmin, $noisepxmax, $noiselinemin, $noiselinemax, $nbcirclemin, $nbcirclemax,$img, $cryptwidth, $cryptheight;
$nbpx = rand($noisepxmin,$noisepxmax);
$nbline = rand($noiselinemin,$noiselinemax);
for ($i=1;$i<$nbpx;$i++) imagesetpixel ($img,rand(0,$cryptwidth-1),rand(0,$cryptheight-1),noisecolor());
for ($i=1;$i<=$nbline;$i++) imageline($img,rand(0,$cryptwidth-1),rand(0,$cryptheight-1),rand(0,$cryptwidth-1),rand(0,$cryptheight-1),noisecolor());
} 


if ($noiseup) {
   ecriture();
   bruit();
   } else {
          bruit();
          ecriture();
          }


// Create the frame
if ($bgframe) {
   $framecol = imagecolorallocate($img,($bgR*3+$charR)/4,($bgG*3+$charG)/4,($bgB*3+$charB)/4);
   imagerectangle($img,0,0,$cryptwidth-1,$cryptheight-1,$framecol);
   }


// Transformations supplÈmentaires: Grayscale et Brouillage
// VÈrifie si la fonction existe dans la version PHP installÈe
if ($cryptgrayscal) imagefilter ( $img,IMG_FILTER_GRAYSCALE);
if ($cryptgaussianblur) imagefilter ( $img,IMG_FILTER_GAUSSIAN_BLUR);

    /* if i comment out these lines, then the file runs fine, but of course does not return an image
    header("Content-type: image/png"); //this is the only header(...) that is included in the file. I am requesting the file directly with the URL.
    imagepng($img);

    imagedestroy ($img);
    unset ($word,$tword);
    unset ($_SESSION['cryptreload']); */

    ?>

注释掉
标题()
,这样它只会发回数据,而不是
图像/png

阅读PHP错误日志,您就会发现确切的错误。很可能是PHP发出警告,这就是您在浏览器上看到此错误的原因。

可能是您的PHP脚本弄乱了您的图像。逻辑错误无法报告,您必须自己查找。要启用常规错误报告,请查看此链接:

要启用错误日志记录,请执行以下操作:

这是个诡计问题,不是吗

您的脚本包含该行

echo('here!'); //prints here to the screen
这会将ASCII字符串“here”前置到PNG数据流,从而破坏图像


提示:如果您下载脚本结果(例如使用
wget
,或在Firefox中简单地“保存页面”),并在编辑器中打开该文件,您将很快发现问题。

在ASP.Net核心应用程序中,您可能会尝试将图片文件放在解决方案下名为Images的文件夹中,但您需要将它们放在wwwroot/images文件夹中:


我希望这可以为在Linux上对.Net核心应用进行故障排除的人节省一个小时: 就我而言,这实际上不是图像的问题。问题是服务器端的大写目录/文件名。在Windows文件系统上,当Linux FS区分大小写时,文件名大小写并不重要。

这里有一个答案可以帮助其他遇到此问题的人:

我发现一个非常常见的原因是图像类型与文件扩展名不匹配。这会导致Web服务器报告错误的mime类型。例如,如果您拍摄一张photoshop图像,将其重命名为.jpg文件,并将其放在Web服务器上,它将不会加载到Firefox中

如果正在解决此问题,请尝试下载文件并验证文件类型是否与jpg匹配。今天,我为一个客户端修复了这个问题,该客户端接收了一个.psd文件,将其重命名为.jpg,将其上载到一个Web服务器,并想知道为什么它不能加载到Firefox中


就我而言,这是VisualStudio的错误。我开始通过img标签将图像添加到代码中,我想是VS用intellisense引导我完成的。有趣的是,它走错了路。这就是它为我所做的:

<img src="~/images/home-couple.jpg" />

本应是:

<img src="images/home-couple.jpg" />


images文件夹的位置就在wwwroot下面。这是一个ASP.NET核心web应用程序。

首先确保在header()命令输出任何内容之前,代码中没有任何部分。 如果在标题前有任何包含,请确保不要使用?>完成php,因为有时这会生成一个字节。
最后,尝试将您的包含内容包装到ob_start()中;和ob_end_clean();因为这将确保不会因为任何其他原因(我曾经有过这种情况)而将随机字节强制转换到输出中。

谢谢您的建议。见我的编辑上面。但我真正的问题是,我如何才能找出错误是什么?如果firefox只是吐出“有一个神秘的错误”,我很难知道如何进行调试,我也不知道该去哪里修复它。好吧,这不是PHP错误(除非你关闭了错误),你对组成图像的数据有问题。你能解释一下你是怎么知道的吗?注释掉标题,然后看到它返回的是乱七八糟的图像,这让你清楚了,这是怎么回事?因为否则你会得到一个PHP错误。现在您得到了PNG数据,所以PHP认为脚本运行良好(可能是这样),但PNG数据被弄乱了,即“无法显示图像”怀疑是200 LoC。。你能把它贴出来吗?只是与图像相关的代码。使用与其他方法相同的调试过程。。。确保错误日志记录已打开(并且错误显示已关闭),随后检查错误日志,检查Fiddler中的请求。这不是一个骗局!这是我忘记删除的调试步骤。图像仍然存在问题