我想要对 PHP 脚本进行 HTTP POST,其中包括文件上传。 PHP 脚本应拒绝任何类型不正确或格式错误的文件。
这意味着
- PHP 脚本在上传完成之前开始执行,
- 它读取文件的前 X 个字节,并且
- 可能会在上传完成之前中止连接。
我该如何执行这些操作?
最佳答案
PHP 无法中止上传。但您可以在文件完全上传后验证$_FILES
。
This feature lets people upload both text and binary files. With PHP's authentication and file manipulation functions, you have full control over who is allowed to upload and what is to be done with the file once it has been uploaded.
参见:
http://php.net/manual/en/features.file-upload.post-method.php
您可以限制 php.ini 中的文件大小
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.net/manual/en/ini.core.php#ini.upload-max-filesize
关于php - 读取标题后中止上传大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11917717/