php max_file_upload,文件上传-PHP文件上传大于upload_max_filesize,并且出现错误

如何在上传到Web服务器的文件大于php upload_max_filesize时发现错误?

我的问题类似于so/large-file-upload-errors-with-php,尽管我的内存限制设置为512M,所以该问题使用的分辨率对我没有帮助.

例如,我尝试上传6.9MB的文件,而我的upload_max_filesize = 6M.我的脚本基本上只是停止执行,而我不知道在哪里或为什么.另外,我已打开错误报告.

另外,我应该注意,我可以使用以下代码正确地上传和处理小于6MB的文件:

if(isset($_FILES['file']['name']) and !empty($_FILES['file']['name'])){

$info = pathinfo($_FILES['file']['name']);

$ext = $info['extension'];

//verify file is of allowed types

if(Mimetypes::isAllowed($ext)){

if(filesize($_FILES['file']['tmp_name']) <= AttachmentUploader::$maxFilesize){

$a = new AttachmentUploader(); //for file uploading

if($a->uploadFile($_FILES['file'], 'incident', $_POST['sys_id'])){

header("location: ".$links['status']."?item=incident&action=update&status=1&place=".urlencode($links['record']."id=".$_POST['sys_id']));

}else{

header("location: ".$links['status']."?item=incident&action=update&status=-1&place=".urlencode($links['record']."id=".$_POST['sys_id']));

}

}else{

$errors[] = 'The file you attempted to upload is too large. 0.5MB is the maximum allowed size for a file. If you are trying to upload an image, it may need to be scaled down.';

}

}else{

$errors[] = 'The file you attempted to upload is not allowed. Acceptable extensions: jpg, gif, bmp, png, xls, doc, docx, txt, pdf';

}

}else{

$errors[] = 'Please attach a file.';

}

我的php.ini设置:

;;;;;;;;;;;;;;;;;;;

; Resource Limits ;

;;;;;;;;;;;;;;;;;;;

max_execution_time = 7200 ; Maximum execution time of each script, in seconds

memory_limit = 512M ; Maximum amount of memory a script may consume (8MB)

;;;;;;;;;;;;;;;;

; File Uploads ;

;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.

file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not

; specified).

upload_tmp_dir = /tmp

; Maximum allowed size for uploaded files.

upload_max_filesize = 6M

解决方法:

错误出现在$_FILES [‘userfile’] [‘error’]中.您只需检查此值是否为UPLOAD_ERR_INI_SIZE即可检测文件是否大于php.ini中定义的最大大小.

资源:

标签:file-upload,php

来源: https://codeday.me/bug/20191209/2096558.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值