各位大大,最近做一个图片上传的东东的时候,发生了这样的报错信息:Warning: imagecreatefromgif() [function.imagecreatefromgif]: '../avatar/original/4af91bddc1329a11ac02d732aee447fe1253363223.gif' is not a valid GIF file in /home2/kinamkco/public_html/board/include/uploadpic.inc.php on line 45我知道这个是gif图片的问题,换张图片就好了,现在问题就是,我不想让这个报错出现,而是直接返回给用户一行字比如"图片格式不对"之类的.我该怎么改代码啊?刚才的报错报的是这一句$image   =   imagecreatefromgif($filename);    怎么写能让程序来判断说当 imagecreatefromgif不成功时返回一个别的值呢?

解决方案 »

  1.   

    手册里有实例:
        $im = @imagecreatefromgif ($imgname); /* Attempt to open */
        if (!$im) { /* See if it failed */
            $im = imagecreate (150, 30); /* Create a blank image */
            $bgc = imagecolorallocate ($im, 255, 255, 255);
            $tc = imagecolorallocate ($im, 0, 0, 0);
            imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
            /* Output an errmsg */
            imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc);
        }
        else echo "图片格式不对";