如何检查上传的文件是视频并确保真正的视频类型

时间:2015-08-24 10:47:51

标签: php

所选文件不是扩展名为avi,mp4等的记事本文件。

我试过了:

$file_allowed =  array('gif','png' ,'jpg','avi','mp4','wmv','mov','flv','webm','ogv','mp3','m4a','ogg','oga');

$uploaded_filename = $_FILES['attachment']['name'];

$file_ext = pathinfo($uploaded_filename, PATHINFO_EXTENSION);

if(!in_array($file_ext,$file_allowed) ) 
{    
  exit;
}

2 个答案:

答案 0 :(得分:0)

尝试使用此变量进行验证

$_FILES["attachment"]["type"];

答案 1 :(得分:0)

尝试更改您的代码:

$file_allowed = array('gif','png' ,'jpg','avi','mp4','wmv','mov','flv','webm','ogv','mp3','m4a','ogg','oga');

$uploaded_filename = $_FILES["attachment"]["type"];

$file_ext = pathinfo($uploaded_filename, PATHINFO_EXTENSION);

if(!in_array($file_ext,$file_allowed) ) {
exit;

}