【发布时间】:2019-11-14 20:52:04
【问题描述】:
我正在设置一个应用程序以接受动态多部分文件上传表单。
我为上传的类型和扩展添加了条件 if 规则。对于满足条件的接受并存储在DB中,对于空的post文件应该被忽略,其余的应该被拒绝。
$allowedExts = array("gif", "jpeg", "jpg", "png", "pdf");
$jumlah_syarat = count($_FILES);
$forwardexts = array("");
$diam = array();
$tolak = array();
foreach ($_FILES as $y => $file){
$ext_file = strtolower(end(explode('.',$file['name'])));
if (($file["type"] == "image/gif")
|| ($file["type"] == "image/jpeg")
|| ($file["type"] == "image/jpg")
|| ($file["type"] == "image/pjpeg")
|| ($file["type"] == "image/x-png")
|| ($file["type"] == "image/png")
|| ($file["type"] == "application/pdf")
&& in_array($ext_file, $allowedExts)) {
$tmpfile = $file['tmp_name'];
$namafile = $noPendaf."-".$idPendaf."-".$y.".".$ext_file;
$kefile = $path.$namafile;
$syarats['idsyarat'][] = $y;
$syarats['filesyarat'][$y] = $namafile;
move_uploaded_file($tmpfile,$kefile);
} elseif(($file["type"] == "") && in_array($ext_file, $forwardexts)){
array_push($diam, 1);
} else{
array_push($tolak, 1);
}
}
对于上面代码的预期结果是等到所有文件上传并在foreach中循环然后被过滤。但是,在文件完全发送(上传)到服务器之前,我总是得到 $torak got array_push 1
【问题讨论】:
-
上传后查看
file_exists()
标签: php codeigniter post upload multipart