脚本宝典收集整理的这篇文章主要介绍了php – 检测上传的文件是否太大,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<form action="uploads.PHP" method="post" enctyPE="multipart/form-data"> <input name="fileupload" type="file" multiple> <button>Upload</button> </form>
; Maximum Allowed size for uploaded files. upload_max_filesize = 5M ; Must be greater than or equal to upload_max_filesize post_max_size = 5M
如果我上传的文件大于5M,则var_dump($_ FILES)为空.我能做到:@H_403_4@
if($_FILES){ echo "Upload done!"; }
如果文件大于5M,则不设置$_FILES.但这有点奇怪.你会怎么做?@H_403_4@
编辑:@H_403_4@
array(0) { }
array(1) { ["fileupload"]=> array(5) { ["name"]=> string(13) "netzerk12.pDF" ["type"]=> string(15) "application/pdf" ["tmp_name"]=> string(22) "/tmp/uploads/PHPWhm8M0" ["error"]=> int(0) ["size"]=> int(352361) } }
// check that post_max_size has not been reached // convert_to_bytes is the function turn `5M` to bytes because $_SERVER['CONTENT_LENGTH'] is in bytes. if (isset($_SERVER['CONTENT_LENGTH']) && (int) $_SERVER['CONTENT_LENGTH'] > convert_to_bytes(ini_get('post_max_size'))) { // ... wITh your LOGic throw new Exception('File too large!'); }
以上是脚本宝典为你收集整理的php – 检测上传的文件是否太大全部内容,希望文章能够帮你解决php – 检测上传的文件是否太大所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。