【发布时间】:2016-01-22 06:47:14
【问题描述】:
我正在做一个上传多张图片的表单,我如何编码以使只有“jpg”、“png”、“gif”的文件能够成功上传并跳过那些不可接受的文件(例如 doc)?目前我的代码只有在所有文件都是可接受的类型时才允许上传,即使只有一个文件不是可接受的文件类型也会提示错误
if ($source_type === NULL) {
echo '<h3>Error</h3><br/>';
echo 'Invalid file type<br/><br/>';
echo '<input type="submit" style="color:#000000" onClick="history.go(-1);return true;" value="Back"><br/><br/>';
}
switch ($source_type) {
case IMAGETYPE_GIF:
$source_gd_image = imagecreatefromgif($source_file_path);
break;
case IMAGETYPE_JPEG:
$source_gd_image = imagecreatefromjpeg($source_file_path);
break;
case IMAGETYPE_PNG:
$source_gd_image = imagecreatefrompng($source_file_path);
break;
default:
return false;
}
【问题讨论】:
标签: php