可能的Xamp或脚本错误?

时间:2015-09-14 20:09:54

标签: php xampp server

首次上传图片并收到此错误。图片为 .jpg 。脚本对我来说似乎没问题。所以我认为问题在于 xamp服务器?

Warning: imagecreatefrompng(): 'C:\xampp\tmp\phpB42E.tmp' is not a
valid PNG file in C:\xampp\htdocs\phphph\check_image.php on line 66
The file you uploaded was not a supported filetype

我在google上搜索并没有找到有用的东西。所以这是脚本的一部分。

 switch ($type){
   case IMAGETYPE_GIF:
        $image = imagecreatefromgif($_FILES['uploadfile']['tmp_name']) or 
        die ('The file you uploaded was not a supported filetype');
        $ext = ' .gif';
        break;
   case IMAGETYPE_JPEG:
        $image = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']) or 
        die ('The file you uploaded was not a supported filetype');
        $ext = ' .jpeg';
   case IMAGETYPE_PNG:
        $image = imagecreatefrompng($_FILES['uploadfile']['tmp_name']) or 
        die ('The file you uploaded was not a supported filetype');
        $ext = ' .png';
        break;
    default:
        die('The file you uploaded was not a supported filetype.');              
   }

1 个答案:

答案 0 :(得分:1)

缺少break

    $ext = ' .jpeg';
  /// missing break here
case IMAGETYPE_PNG:

所以你上传一个jpg,代码继续进入PNG部分,因此你的错误。

所以,不,这对Xamp服务器来说不是问题......这是PEBKAC错误。