Php 为什么下面的代码返回空白页但仍然上传照片

Php 为什么下面的代码返回空白页但仍然上传照片,php,html,forms,Php,Html,Forms,这是我的页面。我的问题是,为什么上传图片时表单返回空白页。在我添加最后一个switch语句之前,它工作得很好。创建图像的那个。(imagejpeg函数)当我不使用switch语句时,它可以工作。但是在我添加switch语句之后,表单消失了。所以我的问题是,switch语句有什么错?还是全部都是代码? $imageFile = $_FILES['image']['tmp_name']; $filename = basename( $_FILES['image']['name'])

这是我的页面。我的问题是,为什么上传图片时表单返回空白页。在我添加最后一个switch语句之前,它工作得很好。创建图像的那个。(imagejpeg函数)当我不使用switch语句时,它可以工作。但是在我添加switch语句之后,表单消失了。所以我的问题是,switch语句有什么错?还是全部都是代码?
    $imageFile = $_FILES['image']['tmp_name']; 
    $filename = basename( $_FILES['image']['name']);

    list($width, $height) = getimagesize($imageFile);
    $picture = getimagesize($imageFile);

    if ($width >= $height) 
    {
        $orig_w = 500;
        $orig_h =($height/$width)*$orig_w;
    } else
    {
        $orig_h = 500;
        $orig_w = ($width/$height)*$orig_h;
    }

    $picture['format'] = strtolower(preg_replace('/^.*?\//', '', $picture['mime']));

    switch( $picture['format'] ) {
    case 'jpg':
    case 'jpeg': 
        $src = imagecreatefromjpeg($imageFile);
    break;
    case 'png':
        $src = imagecreatefrompng($imageFile);
    break;
    case 'gif':
        $src = imagecreatefromgif($imageFile);
    break;
    default:
        echo "unsproted format";
    break;
}

    $tmp = imagecreatetruecolor($orig_w, $orig_h);
    imagecopyresampled($tmp, $src , 0,0,0,0, $orig_w,$orig_h, $width, $height);

    switch( $picture['format'] ) {
        case 'jpg':
        case 'jpeg':
            return imagejpeg($tmp, $folder.$filename, 100);
        break;
        case 'png':
            return imagepng($tmp, $folder.$filename);
        break;
        case 'gif':
            return imagegif($tmp, $folder.$filename);
        break;
        default:
            echo "unsproted format";
        break;
    }

    imagedestroy($tmp);
    imagedestroy($src);
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<h1 > php image upload form </h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
    <p>
        <label for="image" > Image: </label>
        <input type="file" name="image" id="image" /> <br/>
    </p>
    <p>
        <input type="submit" name="submit" value="upload image" />
    </p>
</form>
</body>
</html>
$imageFile=$\u文件['image']['tmp\u名称'];
$filename=basename($_文件['image']['name']);
列表($width,$height)=getimagesize($imageFile);
$picture=getimagesize($imageFile);
如果($width>=$height)
{
$orig_w=500;
$orig_h=($height/$width)*$orig_w;
}否则
{
$orig_h=500;
$orig_w=($width/$height)*$orig_h;
}
$picture['format']=strtolower(preg_replace('/^..*?\/','','$picture['mime']);
开关($picture['format'])){
案件‘jpg’:
案例“jpeg”:
$src=imagecreatefromjpeg($imageFile);
打破
案例“png”:
$src=imagecreatefrompng($imageFile);
打破
案例“gif”:
$src=imagecreatefromformgif($imageFile);
打破
违约:
回声“无保护格式”;
打破
}
$tmp=imagecreatetruecolor($orig\u w,$orig\u h);
imagecopyresampled($tmp、$src、0,0,0、$orig_w、$orig_h、$width、$height);
开关($picture['format'])){
案件‘jpg’:
案例“jpeg”:
返回imagejpeg($tmp,$folder.$filename,100);
打破
案例“png”:
返回imagepng($tmp,$folder.$filename);
打破
案例“gif”:
返回imagegif($tmp,$folder.$filename);
打破
违约:
回声“无保护格式”;
打破
}
图像处理(tmp);
(1)(src);
}
?>
无标题文件
php图像上传表单

我做到了。显然,我不知道switch语句有什么问题(我在php中仍然是一个noob)呵呵。。但将switch语句替换为:

$xtention = explode(".",$filename); 

if ($xtention[1] == 'jpg' || $xtention[1] == 'jpeg' ) {
        imagejpeg($tmp, $folder.$filename, 100);
    }
    elseif ($xtention[1] == 'png') {
        imagepng($tmp, $folder.$filename);
    }
    elseif ($xtention[1] == 'gif') {
        imagegif($tmp, $folder.$filename);
    }
    else {
        echo "unsproted format";
    }

return
语句的作用是什么?可能是…那是赏金。你会在答案旁边看到一个空记号。单击它使其变为绿色