您可以上载任何档案,而Sphp确实没有限制。 你自己需要做限制。
关于客户档案格式限制,请参阅时使用许可证档案格式”。
<input type="file" accept="image/*" /> <!-- all image types -->
<input type="file" accept="audio/*" /> <!-- all audio types -->
对于服务器,您可以按此对上载文档进行过滤。
if(in_array(mime_type($file_path),$allowed_mime_types)){
// save the file
}
$allowed_mime_types = array(
image/jpeg ,
image/jpg ,
image/png ,
image/gif ,
video/mp4
);
/*
For PHP>=5.3.0, you can use php s `finfo_file`([finfo_file](https://www.php.net/manual/en/function.finfo-file.php)) function to get the file infomation about the file.
For PHP<5.3.0, you can use your s system s `file` command to get the file information.
*/
function mime_type($file_path)
{
if (function_exists( finfo_open )) {
$finfo = new finfo(FILEINFO_MIME_TYPE, null);
$mime_type = $finfo->file($file_path);
}
if (!$mime_type && function_exists( passthru ) && function_exists( escapeshellarg )) {
ob_start();
passthru(sprintf( file -b --mime %s 2>/dev/null , escapeshellarg($file_path)), $return);
if ($return > 0) {
ob_end_clean();
$mime_type = null;
}
$type = trim(ob_get_clean());
if (!preg_match( #^([a-z0-9-]+/[a-z0-9-.]+)#i , $type, $match)) {
$mime_type = null;
}
$mime_type = $match[1];
}
return $mime_type;
}