php如何判断上传多个文件的类型及大小等信息

2024-11-27 01:31:00
推荐回答(1个)
回答1:

if (isset($_FILES['upload']['name']))
{
$fcount = count($_FILES['upload']['name']);

for ($i = 0; $i < $fcount; $i++)
{
$fname = $_FILES['upload']['name'][$i];
$path_parts = pathinfo($fname);
if (strtolower($path_parts['extension']) != 'ppt')
{
echo $_FILES['upload']['name'][$i] . ' 不是ppt文件.
' ;
}
}
for ($i = 0; $i < $fcount; $i++)
{
$fsize = (int)$_FILES['uplode']['size'][$i];
if ($fsize > 2048576)
{
echo '文件超过指定的大小: ' . $_FILES['upload']['name'][$i] . ":" . $fsize . '
';
}
}
for ($i = 0; $i < $fcount; $i++)
{
$ferror = $_FILES['uplode']['error'][$i];
if ($ferror)
{
echo '文件上传错误: ' . $_FILES['upload']['name'][$i] . ":" . $ferror. '
';
}
}
} else
{
echo '上传文件不正确.';
}

?>