且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

php在上传表单中检查文件扩展名

更新时间:2022-11-27 11:26:32

Using if( $ext !== 'gif') might not be efficient what if you allow like 20 different extensions

Try

$allowed =  array('gif','png' ,'jpg');
$filename = $_FILES['video_file']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) ) {
    echo 'error';
}