【问题标题】:How to check whether files successfully uploaded如何检查文件是否上传成功
【发布时间】: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


【解决方案1】:

在您的文件上传后添加此代码以检查其是否上传

$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";
}

【讨论】:

  • 我需要确保所有内容都已上传,然后进行处理
猜你喜欢
  • 2019-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-13
  • 2017-11-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多