【问题标题】:php Internal Server Errorphp内部服务器错误
【发布时间】:2013-07-31 10:07:18
【问题描述】:

萨拉姆每个人

我在 fatcow 中托管这个脚本,但它给了我一个“内部服务器错误”。

这是脚本:

<?php 
    create_image(); 
    exit();

    function create_image() 
    {
        // Set the content-type

        // Create the image
        $im = imagecreatefrompng('coupon.png');
        // Create red color
        $red = imagecolorallocate($im, 120, 20, 20);
        //get font arail
        $font = 'font/arial.ttf';
        // Insert variables into coupon

        imagettftext($im, 36, 0, 176, 695, $red, $font, $_POST['Tdesc']);
        imagettftext($im, 36, 0, 176, 985, $red, $font, $_POST['Tclient']);
        imagettftext($im, 40, 0, 176, 1145, $red, $font, $_POST['Texpire']);
        imagettftext($im, 42, 0, 176, 1355, $red, $font, $_POST['Toffre']);

        imagettftext($im, 55, 0, 1796, 422, $red, $font, $_POST['Tcommande']);
        imagettftext($im, 36, 0, 1488, 1000, $red, $font, $_POST['Tadresse']);
        imagettftext($im, 36, 0, 1488, 1290, $red, $font, 'Tél. '. $_POST['Ttel']);
        imagettftext($im, 60, 0, 1488, 1590, $red, $font, $_POST['Tvaleur']);
        imagettftext($im, 60, 0, 1488, 1840, $red, $font, $_POST['Tcode']);

        // Using imagepng() results in clearer text compared with imagejpeg()
        imagepng($im);
        imagedestroy($im);  

    } 
?>

还有错误信息:

内部服务器错误

服务器遇到内部错误或配置错误,并且 无法完成您的请求。

请联系服务器管理员,并告知时间 发生了错误,以及您可能做过的任何事情 导致错误。

有关此错误的更多信息可能在服务器错误中可用 记录。

【问题讨论】:

  • 您的 php 日志在这里会有所帮助。
  • 还要检查服务器日志(即Apache等)。
  • 你尝试过先声明函数然后调用它吗?

标签: php


【解决方案1】:

易于修复:- 只需颠倒您的定义并调用;

<?php

    function create_image() 
    {
        // Set the content-type

        // Create the image
        $im = imagecreatefrompng('coupon.png');
        // Create red color
        $red = imagecolorallocate($im, 120, 20, 20);
        //get font arail
        $font = 'font/arial.ttf';
        // Insert variables into coupon

        imagettftext($im, 36, 0, 176, 695, $red, $font, $_POST['Tdesc']);
        imagettftext($im, 36, 0, 176, 985, $red, $font, $_POST['Tclient']);
        imagettftext($im, 40, 0, 176, 1145, $red, $font, $_POST['Texpire']);
        imagettftext($im, 42, 0, 176, 1355, $red, $font, $_POST['Toffre']);

        imagettftext($im, 55, 0, 1796, 422, $red, $font, $_POST['Tcommande']);
        imagettftext($im, 36, 0, 1488, 1000, $red, $font, $_POST['Tadresse']);
        imagettftext($im, 36, 0, 1488, 1290, $red, $font, 'Tél. '. $_POST['Ttel']);
        imagettftext($im, 60, 0, 1488, 1590, $red, $font, $_POST['Tvaleur']);
        imagettftext($im, 60, 0, 1488, 1840, $red, $font, $_POST['Tcode']);

        // Using imagepng() results in clearer text compared with imagejpeg()
        imagepng($im);
        imagedestroy($im);  

    } 

    create_image(); 
    exit();
?>

您可能还应该添加一个header 调用来设置内容类型。

以后如果你有这种错误你也可以添加:

if (isset($_GET["debug"])){
    ini_set("display_errors", "1");
    error_reporting(E_ALL);
    }

打印任何错误 - if 是可选的;我的大多数文件都有这个,所以我可以将 ?debug 添加到 url,如果我打错字或其他什么,我可以立即看到问题。

【讨论】:

    【解决方案2】:

    检查您的日志,它们可能很有用。尝试使用代码制作一个 php 信息页面 -

    <?php phpinfo(); ?> 
    

    并检查是否已安装 PHP GD 库。您也可以通过编辑 php.ini 文件或将这段代码添加到文件中来尝试让页面向您显示错误。

    ini_set('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting(-1);
    

    【讨论】:

      猜你喜欢
      • 2013-07-02
      • 1970-01-01
      • 1970-01-01
      • 2014-06-08
      • 2018-01-15
      • 2010-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多