Large file uploads PHP solutions (500M or more)

PHP super global variable $ _FILES array to record file upload relevant information.

1.file_uploads=on/off

  Whether to allow http file upload

2.max_execution_time=30

  The maximum allowed script execution time, more than this time will error

3.memory_limit=50M

  The maximum amount of memory that can be allocated to set script, to prevent a runaway script used too much memory, this instruction is only set at compile time 
   to take effect in the case --enable-memory-limit signs

4.upload_max_filesize=20M

  The maximum size allowed to upload a file, this instruction must be less than post_max_size

5.upload_tmp_dir

  Upload file temporary storage directory

6.post_max_size=30M

  Allow post way acceptable maximum size

$ _FILES [ 'myFile'] [ 'name'] original last name of the client file. 

MIME type $ _FILES [ 'myFile'] [ 'type'] file, you need to provide support for the information, such as "image / gif". 

$ _FILES [ 'myFile'] [ 'size'] has uploaded the file size in bytes. 

$ _FILES [ 'myFile'] after [ 'tmp_name'] file is uploaded in the temporary files stored on the server name, usually the system default. It can be specified in the php.ini upload_tmp_dir, but using putenv () from setting is ineffective. 

$ _FILES [ 'myFile'] [ 'error'] and the associated file upload status codes. [ 'Error'] was added in PHP 4.2.0. Here is its description :( they became constant after PHP3.0) 

UPLOAD_ERR_OK 

    值:0; 没有错误发生,文件上传成功。

UPLOAD_ERR_INI_SIZE 

    值:1; 上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值。 

UPLOAD_ERR_FORM_SIZE 

    值:2; 上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。 

  UPLOAD_ERR_PARTIAL 

    值:3; 文件只有部分被上传。 

  UPLOAD_ERR_NO_FILE 

    值:4; 没有文件被上传。 

    值:5; 上传文件大小为0. 
文件被上传结束后,默认地被存储在了临时目录中,这时您必须将它从临时目录中删除或移动到其它地方,如果没有,则会被删除。

也就是不管是否上传成功,脚本执行完后临时目录里的文件肯定会被删除。

附:修改PHP上传文件大小限制的方法

1. 一般的文件上传,除非文件很小.就像一个5M的文件,很可能要超过一分钟才能上传完.

但在php中,默认的该页最久执行时间为 30 秒.就是说超过30秒,该脚本就停止执行.

这就导致出现 无法打开网页的情况.这时我们可以修改 max_execution_time

在php.ini里查找

max_execution_time

默认是30秒.改为

max_execution_time = 0

0表示没有限制

2. 修改 post_max_size 设定 POST 数据所允许的最大大小。此设定也影响到文件上传。

php默认的post_max_size 为2M.如果 POST 数据尺寸大于 post_max_size $_POST 和 $_FILES superglobals 便会为空.
查找 post_max_size .改为

post_max_size = 150M

3. 很多人都会改了第二步.但上传文件时最大仍然为 8M.

为什么呢.我们还要改一个参数upload_max_filesize 表示所上传的文件的最大大小。

查找upload_max_filesize,默认为8M改为

upload_max_filesize = 100M

另外要说明的是,post_max_size 大于 upload_max_filesize 为佳.

上传效果展示:

其他详细配置问题可以参考我写的这篇文章:http://blog.ncmem.com/wordpress/2019/08/09/php%E4%B8%8A%E4%BC%A0%E5%A4%A7%E6%96%87%E4%BB%B6%E9%85%8D%E7%BD%AE/

Guess you like

Origin www.cnblogs.com/songsu/p/12103101.html