阅读标头后中止上传较大的文件 [英] Abort upload large uploads after reading headers
问题描述
我想对包含文件上传的PHP脚本进行HTTP POST.PHP脚本应拒绝任何类型不正确或格式错误的文件.
I want to have a HTTP POST to a PHP script which includes a file upload. The PHP script should reject any file which is not the right type, or otherwise malformed.
这是
- 在完成上传之前,PHP脚本开始执行
- 它读取文件的前X个字节,并且
- 可能在完成上传之前中止连接.
我该如何做?
推荐答案
PHP无法中止上传.但是,在文件完全上传后,您可以验证 $ _ FILES
.
PHP can't abort uploads. But you can validate $_FILES
after the file was completly uploaded.
此功能使人们可以同时上传文本文件和二进制文件.借助PHP的身份验证和文件操作功能,您可以完全控制谁被允许上载以及文件上载后如何处理.
请参阅:
http://php.net/manual/zh/features.file-upload.post-method.php
您可以在php.ini中限制文件大小
You could limit the file size in your php.ini
upload_max_filesize整数
upload_max_filesize integer
上传文件的最大大小.使用整数时,该值以字节为单位.也可以使用本常见问题解答中所述的速记符号.
The maximum size of an uploaded file. When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used.
http://www.php.净/手动/zh/ini.core.php#ini.upload-max-filesize
这篇关于阅读标头后中止上传较大的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!