我有一个PHP脚本,该脚本仅允许从表单上载压缩文件。但是,有时7z文件会分成任意数量的7z文件并附加数字。例如7z.000、7z.001、7z.002,... 如何在以下数组中检查7z。*?谢谢。
$allowed = ['7z', 'bzip', 'bzip2', 'zip', 'zipx'];
这是整个脚本。
<?php
// header('Content-Type: application/json');
$allowed = ['7z', '000', '7z', '7z.*', 'bzip', 'bzip2', 'zip', 'zipx'];
$processed = [];
foreach($_FILES['files']['name'] as $key => $name) {
if($_FILES['files']['error'][$key] === 0) {
$temp = $_FILES['files']['tmp_name'][$key];
$ext = explode('.', $name);
$ext = strtolower(end($ext));
//echo $file = $name;
if (in_array($ext, $allowed) && move_uploaded_file($temp, "uploads/{$name}")) {
$processed[] = array(
'name' => $name,
'file' => $name,
'uploaded' => true
);
} else {
$processed[] = array(
'name' => $name,
'uploaded' => false
);
}
}
}
echo json_encode($processed);
文件如下所示: somefilename.7z somefilename.7z.000甚至大于filename.7z.009