PHP安全上传图片的方法_PHP
程序员文章站
2022-06-04 17:02:07
...
本文实例讲述了PHP安全上传图片的方法。分享给大家供大家参考。具体分析如下:
"; echo ""; } else echo "'$name' is not an accepted image file"; } else echo "No image has been uploaded"; echo "
这段代码用于上传图片,可以根据图片类型检测图片是否安全,不是简单的检测扩展名
_END; if ($_FILES) { $name = $_FILES['filename']['name']; switch($_FILES['filename']['type']) { case 'image/jpeg': $ext = 'jpg'; break; case 'image/gif': $ext = 'gif'; break; case 'image/png': $ext = 'png'; break; case 'image/tiff': $ext = 'tif'; break; default: $ext = ''; break; } if ($ext) { $n = "image.$ext"; move_uploaded_file($_FILES['filename']['tmp_name'], $n); echo "Uploaded image '$name' as '$n':PHP Form Upload
"; echo ""; } else echo "'$name' is not an accepted image file"; } else echo "No image has been uploaded"; echo "
下一篇: 编写自动贩卖机程序