我正在设置一个应用程序以接受动态的多部分文件上传表单。
我为上传的类型和扩展名添加了条件if规则。要使有条件的满足被接受并存储在DB中,对于空的发布文件应被忽略,而其余的则应被拒绝。
$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,然后进行过滤。但是,在文件完全发送(上载)到服务器之前,我总是得到$ tolak得到array_push 1
答案 0 :(得分:0)
在文件上传后添加此代码,以检查文件是否上传
$file_pointer = '';//here you need to pass your absolute path
if (file_exists($file_pointer)) {
echo "The file $file_pointer exists";
}else {
echo "The file $file_pointer does not exists";
}