php - 读取标题后中止上传大文件

标签 php http sockets

我想要对 PHP 脚本进行 HTTP POST,其中包括文件上传。 PHP 脚本应拒绝任何类型不正确或格式错误的文件。

这意味着

  1. PHP 脚本在上传完成之前开始执行,
  2. 它读取文件的前 X 个字节,并且
  3. 可能会在上传完成之前中止连接。

我该如何执行这些操作?

最佳答案

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/

相关文章:

PHP 和 mysql 在 Linux 中与 apache tomcat 6 集成

php - MySQL:如果今年的这个月是一月,如何查询上个月的数据?

php - 使用php从txt文件中删除换行符

python - 通过 http header 等即时返回文本(在变量中)作为 .txt 文件

json - 使用 http post apache solr 插入新文档 json

php - Laravel Remote/SSH 捕获 SSH2 异常

Ruby Net::HTTP 超时

Java:无法在套接字 in.readLine() 之后写入套接字

javascript - Nodejs - Express - 我无法连接到 Socket IO 对象可能是什么问题?

java - 如何在java中接收socketServer上的对象