+ -
当前位置:首页 → 问答吧 → 深入理解PHP原理之文件上传

深入理解PHP原理之文件上传

时间:2008-11-21

来源:互联网

· 作者:laruence(http://www.laruence.com/)
· 本文地址: http://www.laruence.com/2008/11/07/586.html
· 转载请注明出处                                       

     今天研究PHP注册POST/GET大变量的时候,看到了关于这块的一些东西,跟踪了半天,,先记录下来,免得以后再如此麻烦的跟踪
处理器注册:
[mod_php5.c, mod_php5模块初始化]
php_init_handler(server_rec *s, pool *p)
    ->[main/SAPI.c]sapi_startup(&apache_sapi_module)
        ->[main/SAPI.c]
sapi_globals_ctor(&sapi_globals)
            ->[main/php_content_types.c]php_setup_sapi_content_types(TSRMLS_C)
                ->[main/php_content_types.c
php_post_entries如下]sapi_register_post_entries(php_post_entries
TSRMLS_CC)
                    ->[main/SAPI.c]sapi_register_post_entry(p
TSRMLS_CC)

  如下面的代码,共注册了俩个处理器,分别处理post数据和文件上传。
  注1:参看在PHP Module中获取$_GET/$_POST/$_COOKIE的方法研究
[main/rfc1867.h]
      #define
MULTIPART_CONTENT_TYPE
"multipart/form-data"

[main/php_content_types.h]
     #define
DEFAULT_POST_CONTENT_TYPE
"application/x-www-form-urlencoded"

[main/SAPI.c]
struct
_sapi_post_entry
{
char *content_type;
        uint
content_type_len;
        void
(*post_reader)(TSRMLS_D);
        void
(*post_handler)(char *content_type_dup, void *arg
TSRMLS_DC);
    };
  [main/php_content_types.c]
static
sapi_post_entry
php_post_entries[] = {
{
DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_std_post_handler
},
        {
MULTIPART_CONTENT_TYPE,    sizeof(MULTIPART_CONTENT_TYPE)-1,    NULL,                         rfc1867_post_handler
},
        {
NULL, 0, NULL, NULL
}
};

那么对于rfc1867_post_handler函数来说,我罗列出源码如下, 加了我的注释.
(帖子超长了, 看原文,谢谢)

作者: laruence   发布时间: 2008-11-21

C没学好,看不懂,问下楼主,看这东东是不是C一定要撑握熟练啊。

作者: studyphp   发布时间: 2008-12-03

好東西啊.  剛好要用到上傳的部分.

作者: zxwo0o   发布时间: 2008-12-12

c一定要非常熟练!不然很难懂或者根本不懂!

作者: liexusong   发布时间: 2008-12-12

感谢分享

作者: 0hudu   发布时间: 2008-12-13