【问题标题】:jquery easyupload plugin not uploading pdf filesjquery easyupload插件不上传pdf文件
【发布时间】:2019-01-16 19:47:40
【问题描述】:

我正在使用easyupload jquery

源: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);
		} 

我两天都想不通是什么问题。

谁能帮帮我,在此先感谢。

【问题讨论】:

  • 你检查我的答案了吗?
  • @KhoaTruongDinh 还没有,我现在想检查,但你能解释得更好吗?

标签: javascript php jquery


【解决方案1】:

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

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

【讨论】:

  • 用你给我的代码试过,总是得到“超过文件大小限制”。即使限制 9999999999999999 和文件大小 4.2MB
  • 你检查你的 php.ini 的限制了吗?尝试使用小于 2MB 的较小文件。
  • ini_get('post_max_size');响应“8M”
  • upload_max_filesize 怎么样?
  • 是的,你是对的,最好两个都增加:stackoverflow.com/questions/23686505/…。记住post_max_size 必须大于upload_max_filesize
猜你喜欢
  • 2017-03-15
  • 2012-01-30
  • 1970-01-01
  • 2013-12-19
  • 1970-01-01
  • 2013-09-18
  • 2016-01-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多