PHP文件上传 - 内存处理上的CGI [英] PHP File upload - memory handling on CGI

查看:225
本文介绍了PHP文件上传 - 内存处理上的CGI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道PHP如何处理一个文件上传。我心中已经文件上传将被拆分上载结束后的块,将被组装。有没有这个事实的验证?这将有助于了解一个文件上传的处理和设置。
是mod_php的处理或CGI一样的吗? mod_php,并且更与Apache绑在了一起。 CGI有读取一个流,然后做它的神奇。

内存是如何参与这一进程。

这是正确的?


  1. 的Apache处理 HTTP请求

  2. 的Apache调用PHP在CGI和数据流(管道)

  3. PHP分割输入一定大小的区块,达不到内存限制

  4. 流端找到

  5. PHP组装分割文件合并成一个文件,并删除分割文件

  6. 有关文件上传信息将被保存到$ _FILES


解决方案

PHP并读取该文件中块,但它并没有将它们写入单个文件,然后重新组合它们,让他们写入到同一临时文件是一个你在$ _FILES获得。

这对mod_php,并且和CGI相同的。

这里的负责code:<一href=\"http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/main/rfc1867.c?revision=307583&view=markup#l1065\" rel=\"nofollow\">http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/main/rfc1867.c?revision=307583&view=markup#l1065

I'm wondering how PHP handles a file upload. I'v read a file upload will be split in chunks and will be assembled after the upload has finished. Is there any verification of this fact? This will help to understand the handling and settings for a file upload. Is the handling of mod_php or CGI the same? mod_php is more tied together with Apache. CGI has to read a stream and then do it's magic.

How is the memory involved in this process.

Is this correct?

  1. Apache handles HTTP request
  2. Apache calls PHP over CGI and streams data (pipe)
  3. PHP splits input in chunks of a certain size to not reach the memory limit
  4. Stream end is found
  5. PHP assembles split files into one file and will delete the split files
  6. Information about file upload will be save into $_FILES

解决方案

PHP does read the file in chunks but it doesn't write them to individual files and then recombine them, it keeps writing them to the same temporary file which is the one you get in $_FILES.

It's the same for mod_php and CGI.

Here's the responsible code: http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/main/rfc1867.c?revision=307583&view=markup#l1065

这篇关于PHP文件上传 - 内存处理上的CGI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆