dtd14883 2019-07-04 07:10
浏览 120

如何检查文件是否成功上传

I'm setting up an application to accept a dynamic multipart files upload form.

I add a conditional if rule for uploaded type and extension. For conditional fulfilled to be accepted and store in DB, and for the empty post file should be ignored, for the rest should be got rejected.

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

For the expected result of the code above is to wait until all files uploaded and loop in foreach and then be filtered. But, I always get $tolak got array_push 1 before the file fully sent (uploaded) to the server

  • 写回答

1条回答 默认 最新

  • dragon8837 2019-07-04 07:34
    关注

    Add this code after your file uploaded to check its uploaded or not

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

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?