jQuery easyupload插件未上传pdf文件

时间:2018-08-09 11:10:40

标签: javascript php jquery

我正在使用easyupload jQuery

Src:https://github.com/fater/jquery-easyupload

我正在尝试上传文件(图像,doc,docx完美上传),但是pdf显示我错误,但没有解释错误。

我的代码:

elseif ($type == "upload_file") {
			$target_dir = $_SERVER['DOCUMENT_ROOT']."/admin2/uploads/images/";
			$target_file = $target_dir . basename($_FILES["file"]["name"]);
			$uploadOk = 1;
			$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
			// Check if image file is a actual image or fake image
			if (file_exists($target_file)) {$data['status'] = "error"; $data['msg'] = $BNL->msg("הקובץ עם השם הזה כבר קיים במערכת.");}
			elseif ($_FILES["file"]["size"] > 5000000) {$data['status'] = "error"; $data['msg'] = $BNL->msg("המגבלה של העלאת קובץ היא 5MB");}
			elseif($imageFileType != "pdf" && $imageFileType != "doc" && $imageFileType != "docx" ) {$data['status'] = "error"; $data['msg'] = $BNL->msg("הקבצים המותרים הם PDF, DOC, DOCX");}
			else {
				if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
					$data['msg'] = $BNL->msg("הקובץ ". basename( $_FILES["file"]["name"]). " הועלה בהצלחה.", true);
					$_SESSION['file'] = basename( $_FILES["file"]["name"]);
				} else {
					//$data['msg'] = $BNL->msg("סליחה, הייתה בעיה בהעלאת הקובץ.");
					$data['msg'] = $_FILES['file']['error']; // Print "1"
				}
			}
			echo json_encode($data);
		} 

我无法弄清楚我要解决两天的问题。

任何人都可以帮助我,谢谢。

1 个答案:

答案 0 :(得分:0)

在这种情况下,我们需要检查

upload_max_filesizepost_max_size

http://php.net/manual/en/features.file-upload.php

<?php
try {
    if (empty($_FILES)) {
        new \Exception('$_FILES array is empty.');
    } else {
        if (isset($_FILES['file']) && !empty($_FILES['file'])) {
            //Check error code
            #https://github.com/zendframework/zend-validator/blob/master/src/File/Upload.php#L25
        };

    }

} catch (Throwable $exception) {
    echo $exception->getMessage();
}

https://github.com/zendframework/zend-validator/blob/master/src/File/Upload.php#L25

了解更多:$_FILE upload large file gives error 1 even though upload_max_size is bigger than the file size