首页 > 其他 > 详细

上传文件,提示文件不存在的解决方法

时间:2014-07-08 00:05:13      阅读:675      评论:0      收藏:0      [点我收藏+]

在做公司的一个项目中,需要上传文件,使用的是AjaxUpload JS组件,选择完文件后,发送请求到指定接口,随即返回服务器上文件的相对路径,然后PHP再做其他工作(这不是重点)

 

处理上传的PHP程序,限制其文件大小为20M

php.ini中

post_max_size 20M

upload_max_filesize 20M

memory_limit 256M

ngint.conf中

client_max_body_size 518M

 

上传20M以下的文件,没有问题,但是,例如上传80M的文件,会报错,文件不存在,

if ( ! isset($_FILES[$field]))
{
  $this->set_error(‘upload_no_file_selected‘);
  return FALSE;
}

网上的解决方法是 设置 php.ini和nginx.conf中相应的属性,仍然报错,后来参考了鸟哥的一篇文章,才找到原因

解决方法:

php.ini中的post_max_size和upload_max_filesize 的值要大些,不能仅限于规定的值,比如这个20M,根据情况,这里设置200M,再次上传80M的文件,根据PHP程序本身的 $_FILES[‘file‘][‘error‘] 可得出 文件大小 超过限制 这样的提示

  1. SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
  2. {
  3.         char *boundary, *s=NULL, *boundary_end = NULL, *start_arr=NULL, *array_index=NULL;
  4.         char *temp_filename=NULL, *lbuf=NULL, *abuf=NULL;
  5.         int boundary_len=0, total_bytes=0, cancel_upload=0, is_arr_upload=0, array_len=0;
  6.         int max_file_size=0, skip_upload=0, anonindex=0, is_anonymous;
  7.         zval *http_post_files=NULL; HashTable *uploaded_files=NULL;
  8. #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
  9.         int str_len = 0, num_vars = 0, num_vars_max = 2*10, *len_list = NULL;
  10.         char **val_list = NULL;
  11. #endif
  12.         zend_bool magic_quotes_gpc;
  13.         multipart_buffer *mbuff;
  14.         zval *array_ptr = (zval *) arg;
  15.         int fd=-1;
  16.         zend_llist header;
  17.         void *event_extra_data = NULL;
  18.         int llen = 0;
  19.  
  20.           /**
  21.            *检查是否超出最大上传文件大小,这是重点
  22.            *从request_global中取出request_info结构体中的content_length元素,这个content_length应该是http 头信息中发给服务器的
  23.            *如果content_length 大于php.ini中设置的post_max_size,就会由sapi_errror触发一个warning,这个warning不会被php接受(还有待研究)
  24.            *通过nginx的log日志中也能发现此warning
  25.            *bubuko.com,布布扣
  26.            */  
  27.         if (SG(request_info).content_length > SG(post_max_size)) {
  28.                 sapi_module.sapi_error(E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", SG(request_info).content_length, SG(post_max_size));
  29.                 return;
  30.         }
  31.  
  32.         //取得上传文件的分隔符
  33.         boundary = strstr(content_type_dup, "boundary");
  34.         if (!boundary || !(boundary=strchr(boundary, ‘=‘))) {
  35.                 sapi_module.sapi_error(E_WARNING, "Missing boundary in multipart/form-data POST data");
  36.                 return;
  37.         }
  38.  
  39.         boundary++;
  40.         boundary_len = strlen(boundary);
  41.  
  42.         if (boundary[0] == ‘"‘) {
  43.                 boundary++;
  44.                 boundary_end = strchr(boundary, ‘"‘);
  45.                 if (!boundary_end) {
  46.                         sapi_module.sapi_error(E_WARNING, "Invalid boundary in multipart/form-data POST data");
  47.                         return;
  48.                 }
  49.         } else {
  50.                 /* search for the end of the boundary */
  51.                 boundary_end = strchr(boundary, ‘,‘);
  52.         }
  53.         if (boundary_end) {
  54.                 boundary_end[0] = ‘‘;
  55.                 boundary_len = boundary_end-boundary;
  56.         }
  57.  
  58.         /* Initialize the buffer */
  59.         if (!(mbuff = multipart_buffer_new(boundary, boundary_len))) {
  60.                 sapi_module.sapi_error(E_WARNING, "Unable to initialize the input buffer");
  61.                 return;
  62.         }
  63.  
  64.         //初始化$_FILE变量
  65.         zend_hash_init(&PG(rfc1867_protected_variables), 5, NULL, NULL, 0);
  66.  
  67.         ALLOC_HASHTABLE(uploaded_files);
  68.         zend_hash_init(uploaded_files, 5, NULL, (dtor_func_t) free_estring, 0);
  69.         SG(rfc1867_uploaded_files) = uploaded_files;
  70.  
  71.         ALLOC_ZVAL(http_post_files);
  72.         array_init(http_post_files);
  73.         INIT_PZVAL(http_post_files);
  74.         PG(http_globals)[TRACK_VARS_FILES] = http_post_files; //TRACK_VARS_FILE正是_FILE在php_core_globals.http_globals中的index (注1)
  75.  
  76. #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
  77.         if (php_mb_encoding_translation(TSRMLS_C)) {
  78.                 val_list = (char **)ecalloc(num_vars_max+2, sizeof(char *));
  79.                 len_list = (int *)ecalloc(num_vars_max+2, sizeof(int));
  80.         }
  81. #endif
  82.         zend_llist_init(&header, sizeof(mime_header_entry), (llist_dtor_func_t) php_free_hdr_entry, 0);
  83.  
  84.         if (php_rfc1867_callback != NULL) {
  85.                 multipart_event_start event_start;
  86.  
  87.                 event_start.content_length = SG(request_info).content_length;
  88.                 if (php_rfc1867_callback(MULTIPART_EVENT_START, &event_start, &event_extra_data TSRMLS_CC) == FAILURE) {
  89.                         goto fileupload_done;
  90.                 }
  91.         }
  92.  
  93.         while (!multipart_buffer_eof(mbuff TSRMLS_CC))
  94.         {
  95.                 char buff[FILLUNIT];
  96.                 char *cd=NULL,*param=NULL,*filename=NULL, *tmp=NULL;
  97.                 size_t blen=0, wlen=0;
  98.                 off_t offset;
  99.  
  100.                 zend_llist_clean(&header);
  101.  
  102.                 if (!multipart_buffer_headers(mbuff, &header TSRMLS_CC)) {
  103.                         goto fileupload_done;
  104.                 }
  105.  
  106.                 if ((cd = php_mime_get_hdr_value(header, "Content-Disposition"))) {
  107.                         char *pair=NULL;
  108.                         int end=0;
  109.  
  110.                         while (isspace(*cd)) {
  111.                                 ++cd;
  112.                         }
  113.  
  114.                         while (*cd && (pair = php_ap_getword(&cd, ‘;‘)))
  115.                         {
  116.                                 char *key=NULL, *word = pair;
  117.  
  118.                                 while (isspace(*cd)) {
  119.                                         ++cd;
  120.                                 }
  121.  
  122.                                 if (strchr(pair, ‘=‘)) {
  123.                                         key = php_ap_getword(&pair, ‘=‘);
  124.  
  125.                                         if (!strcasecmp(key, "name")) {
  126.                                                 if (param) {
  127.                                                         efree(param);
  128.                                                 }
  129.                                                 param = php_ap_getword_conf(&pair TSRMLS_CC);
  130.                                         } else if (!strcasecmp(key, "filename")) {
  131.                                                 if (filename) {
  132.                                                         efree(filename);
  133.                                                 }
  134.                                                 filename = php_ap_getword_conf(&pair TSRMLS_CC);
  135.                                         }
  136.                                 }
  137.                                 if (key) {
  138.                                         efree(key);
  139.                                 }
  140.                                 efree(word);
  141.                         }
  142.  
  143.                         /* Normal form variable, safe to read all data into memory */
  144.                         if (!filename && param) {
  145.                                 unsigned int value_len;
  146.                                 char *value = multipart_buffer_read_body(mbuff, &value_len TSRMLS_CC);
  147.                                 unsigned int new_val_len; /* Dummy variable */
  148.  
  149.                                 if (!value) {
  150.                                         value = estrdup("");
  151.                                 }
  152.  
  153.                                 if (sapi_module.input_filter(PARSE_POST, param, &value, value_len, &new_val_len TSRMLS_CC)) {
  154.                                         if (php_rfc1867_callback != NULL) {
  155.                                                 multipart_event_formdata event_formdata;
  156.                                                 size_t newlength = 0;
  157.  
  158.                                                 event_formdata.post_bytes_processed = SG(read_post_bytes);
  159.                                                 event_formdata.name = param;
  160.                                                 event_formdata.value = &value;
  161.                                                 event_formdata.length = new_val_len;
  162.                                                 event_formdata.newlength = &newlength;
  163.                                                 if (php_rfc1867_callback(MULTIPART_EVENT_FORMDATA, &event_formdata, &event_extra_data TSRMLS_CC) == FAILURE) {
  164.                                                         efree(param);
  165.                                                         efree(value);
  166.                                                         continue;
  167.                                                 }
  168.                                                 new_val_len = newlength;
  169.                                         }
  170.  
  171. #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
  172.                                         if (php_mb_encoding_translation(TSRMLS_C)) {
  173.                                                 php_mb_gpc_stack_variable(param, value, &val_list, &len_list,
  174.                                                                                                   &num_vars, &num_vars_max TSRMLS_CC);
  175.                                         } else {
  176.                                                 safe_php_register_variable(param, value, new_val_len, array_ptr, 0 TSRMLS_CC);
  177.                                         }
  178. #else
  179.                                         safe_php_register_variable(param, value, new_val_len, array_ptr, 0 TSRMLS_CC);
  180. #endif
  181.                                 } else if (php_rfc1867_callback != NULL) {
  182.                                         multipart_event_formdata event_formdata;
  183.  
  184.                                         event_formdata.post_bytes_processed = SG(read_post_bytes);
  185.                                         event_formdata.name = param;
  186.                                         event_formdata.value = &value;
  187.                                         event_formdata.length = value_len;
  188.                                         event_formdata.newlength = NULL;
  189.                                         php_rfc1867_callback(MULTIPART_EVENT_FORMDATA, &event_formdata, &event_extra_data TSRMLS_CC);
  190.                                 }
  191.  
  192.                                 if (!strcasecmp(param, "MAX_FILE_SIZE")) {
  193.                                         max_file_size = atol(value);
  194.                                 }
  195.  
  196.                                 efree(param);
  197.                                 efree(value);
  198.                                 continue;
  199.                         }
  200.  
  201.                         /* If file_uploads=off, skip the file part */
  202.                         if (!PG(file_uploads)) {
  203.                                 skip_upload = 1;
  204.                         }
  205.  
  206.                         /* Return with an error if the posted data is garbled */
  207.                         if (!param && !filename) {
  208.                                 sapi_module.sapi_error(E_WARNING, "File Upload Mime headers garbled");
  209.                                 goto fileupload_done;
  210.                         }
  211.  
  212.                         if (!param) {
  213.                                 is_anonymous = 1;
  214.                                 param = emalloc(MAX_SIZE_ANONNAME);
  215.                                 snprintf(param, MAX_SIZE_ANONNAME, "%u", anonindex++);
  216.                         } else {
  217.                                 is_anonymous = 0;
  218.                         }
  219.  
  220.                         /* New Rule: never repair potential malicious user input */
  221.                         if (!skip_upload) {
  222.                                 char *tmp = param;
  223.                                 long c = 0;
  224.  
  225.                                 while (*tmp) {
  226.                                         if (*tmp == ‘[‘) {
  227.                                                 c++;
  228.                                         } else if (*tmp == ‘]‘) {
  229.                                                 c--;
  230.                                                 if (tmp[1] && tmp[1] != ‘[‘) {
  231.                                                         skip_upload = 1;
  232.                                                         break;
  233.                                                 }
  234.                                         }
  235.                                         if (c < 0) {
  236.                                                 skip_upload = 1;
  237.                                                 break;
  238.                                         }
  239.                                         tmp++;
  240.                                 }
  241.                         }
  242.  
  243.                         total_bytes = cancel_upload = 0;
  244.  
  245.                         if (!skip_upload) {
  246.                                 /* Handle file */
  247.                                 fd = php_open_temporary_fd_ex(PG(upload_tmp_dir), "php", &temp_filename, 1 TSRMLS_CC);
  248.                                 if (fd==-1) {
  249.                                         sapi_module.sapi_error(E_WARNING, "File upload error - unable to create a temporary file");
  250.                                         cancel_upload = UPLOAD_ERROR_E;
  251.                                 }
  252.                         }
  253.  
  254.                         if (!skip_upload && php_rfc1867_callback != NULL) {
  255.                                 multipart_event_file_start event_file_start;
  256.  
  257.                                 event_file_start.post_bytes_processed = SG(read_post_bytes);
  258.                                 event_file_start.name = param;
  259.                                 event_file_start.filename = &filename;
  260.                                 if (php_rfc1867_callback(MULTIPART_EVENT_FILE_START, &event_file_start, &event_extra_data TSRMLS_CC) == FAILURE) {
  261.                                         if (temp_filename) {
  262.                                                 if (cancel_upload != UPLOAD_ERROR_E) { /* file creation failed */
  263.                                                         close(fd);
  264.                                                         unlink(temp_filename);
  265.                                                 }
  266.                                                 efree(temp_filename);
  267.                                         }
  268.                                         temp_filename="";
  269.                                         efree(param);
  270.                                         efree(filename);
  271.                                         continue;
  272.                                 }
  273.                         }
  274.  
  275.                         if (skip_upload) {
  276.                                 efree(param);
  277.                                 efree(filename);
  278.                                 continue;
  279.                         }
  280.  
  281.                         if(strlen(filename) == 0) {
  282. #if DEBUG_FILE_UPLOAD
  283.                                 sapi_module.sapi_error(E_NOTICE, "No file uploaded");
  284. #endif
  285.                                 cancel_upload = UPLOAD_ERROR_D;
  286.                         }
  287.  
  288.                         offset = 0;
  289.                         end = 0;
  290.                         while (!cancel_upload && (blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end TSRMLS_CC)))
  291.                         {
  292.                                 if (php_rfc1867_callback != NULL) {
  293.                                         multipart_event_file_data event_file_data;
  294.  
  295.                                         event_file_data.post_bytes_processed = SG(read_post_bytes);
  296.                                         event_file_data.offset = offset;
  297.                                         event_file_data.data = buff;
  298.                                         event_file_data.length = blen;
  299.                                         event_file_data.newlength = &blen;
  300.                                         if (php_rfc1867_callback(MULTIPART_EVENT_FILE_DATA, &event_file_data, &event_extra_data TSRMLS_CC) == FAILURE) {
  301.                                                 cancel_upload = UPLOAD_ERROR_X;
  302.                                                 continue;
  303.                                         }
  304.                                 }
  305.  
  306.                                 if (PG(upload_max_filesize) > 0 && total_bytes > PG(upload_max_filesize)) {
  307. #if DEBUG_FILE_UPLOAD
  308.                                         sapi_module.sapi_error(E_NOTICE, "upload_max_filesize of %ld bytes exceeded - file [%s=%s] not saved", PG(upload_max_filesize), param, filename);
  309. #endif
  310.                                         cancel_upload = UPLOAD_ERROR_A;
  311.                                 } else if (max_file_size && (total_bytes > max_file_size)) {
  312. #if DEBUG_FILE_UPLOAD
  313.                                         sapi_module.sapi_error(E_NOTICE, "MAX_FILE_SIZE of %ld bytes exceeded - file [%s=%s] not saved", max_file_size, param, filename);
  314. #endif
  315.                                         cancel_upload = UPLOAD_ERROR_B;
  316.                                 } else if (blen > 0) {
  317.  
  318.                                         wlen = write(fd, buff, blen);
  319.  
  320.                                         if (wlen == -1) {
  321.                                                 /* write failed */
  322. #if DEBUG_FILE_UPLOAD
  323.                                                 sapi_module.sapi_error(E_NOTICE, "write() failed - %s", strerror(errno));
  324. #endif
  325.                                                 cancel_upload = UPLOAD_ERROR_F;
  326.                                         } else if (wlen < blen) {
  327. #if DEBUG_FILE_UPLOAD
  328.                                                 sapi_module.sapi_error(E_NOTICE, "Only %d bytes were written, expected to write %d", wlen, blen);
  329. #endif
  330.                                                 cancel_upload = UPLOAD_ERROR_F;
  331.                                         } else {
  332.                                                 total_bytes += wlen;
  333.                                         }
  334.  
  335.                                         offset += wlen;
  336.                                 }
  337.                         }
  338.                         if (fd!=-1) { /* may not be initialized if file could not be created */
  339.                                 close(fd);
  340.                         }
  341.                         if (!cancel_upload && !end) {
  342. #if DEBUG_FILE_UPLOAD
  343.                                 sapi_module.sapi_error(E_NOTICE, "Missing mime boundary at the end of the data for file %s", strlen(filename) > 0 ? filename : "");
  344. #endif
  345.                                 cancel_upload = UPLOAD_ERROR_C;
  346.                         }
  347. #if DEBUG_FILE_UPLOAD
  348.                         if(strlen(filename) > 0 && total_bytes == 0 && !cancel_upload) {
  349.                                 sapi_module.sapi_error(E_WARNING, "Uploaded file size 0 - file [%s=%s] not saved", param, filename);
  350.                                 cancel_upload = 5;
  351.                         }
  352. #endif
  353.  
  354.                         if (php_rfc1867_callback != NULL) {
  355.                                 multipart_event_file_end event_file_end;
  356.  
  357.                                 event_file_end.post_bytes_processed = SG(read_post_bytes);
  358.                                 event_file_end.temp_filename = temp_filename;
  359.                                 event_file_end.cancel_upload = cancel_upload;
  360.                                 if (php_rfc1867_callback(MULTIPART_EVENT_FILE_END, &event_file_end, &event_extra_data TSRMLS_CC) == FAILURE) {
  361.                                         cancel_upload = UPLOAD_ERROR_X;
  362.                                 }
  363.                         }
  364.  
  365.                         if (cancel_upload) {
  366.                                 if (temp_filename) {
  367.                                         if (cancel_upload != UPLOAD_ERROR_E) { /* file creation failed */
  368.                                                 unlink(temp_filename);
  369.                                         }
  370.                                         efree(temp_filename);
  371.                                 }
  372.                                 temp_filename="";
  373.                         } else {
  374.                                 zend_hash_add(SG(rfc1867_uploaded_files), temp_filename, strlen(temp_filename) + 1, &temp_filename, sizeof(char *), NULL);
  375.                         }
  376.  
  377.                         /* is_arr_upload is true when name of file upload field
  378. * ends in [.*]
  379. * start_arr is set to point to 1st [
  380. */
  381.                         is_arr_upload = (start_arr = strchr(param,‘[‘)) && (param[strlen(param)-1] == ‘]‘);
  382.  
  383.                         if (is_arr_upload) {
  384.                                 array_len = strlen(start_arr);
  385.                                 if (array_index) {
  386.                                         efree(array_index);
  387.                                 }
  388.                                 array_index = estrndup(start_arr+1, array_len-2);
  389.                         }
  390.  
  391.                         /* Add $foo_name */
  392.                         if (llen < strlen(param) + MAX_SIZE_OF_INDEX + 1) {
  393.                                 llen = strlen(param);
  394.                                 lbuf = (char *) safe_erealloc(lbuf, llen, 1, MAX_SIZE_OF_INDEX + 1);
  395.                                 llen += MAX_SIZE_OF_INDEX + 1;
  396.                         }
  397.  
  398.                         if (is_arr_upload) {
  399.                                 if (abuf) efree(abuf);
  400.                                 abuf = estrndup(param, strlen(param)-array_len);
  401.                                 snprintf(lbuf, llen, "%s_name[%s]", abuf, array_index);
  402.                         } else {
  403.                                 snprintf(lbuf, llen, "%s_name", param);
  404.                         }
  405.  
  406. #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
  407.                         if (php_mb_encoding_translation(TSRMLS_C)) {
  408.                                 if (num_vars>=num_vars_max){
  409.                                         php_mb_gpc_realloc_buffer(&val_list, &len_list, &num_vars_max,
  410.                                                                                           1 TSRMLS_CC);
  411.                                 }
  412.                                 val_list[num_vars] = filename;
  413.                                 len_list[num_vars] = strlen(filename);
  414.                                 num_vars++;
  415.                                 if(php_mb_gpc_encoding_detector(val_list, len_list, num_vars, NULL TSRMLS_CC) == SUCCESS) {
  416.                                         str_len = strlen(filename);
  417.                                         php_mb_gpc_encoding_converter(&filename, &str_len, 1, NULL, NULL TSRMLS_CC);
  418.                                 }
  419.                                 s = php_mb_strrchr(filename, ‘\‘ TSRMLS_CC);
  420. if ((tmp = php_mb_strrchr(filename, ‘/‘ TSRMLS_CC)) > s) {
  421. s = tmp;
  422. }
  423. num_vars--;
  424. goto filedone;
  425. }
  426. #endif
  427. /* The check should technically be needed for win32 systems only where
  428. * it is a valid path separator. However, IE in all it‘s wisdom always sends
  429.                          * the full path of the file on the user‘s filesystem, which means that unless
  430. * the user does basename() they get a bogus file name. Until IE‘s user base drops
  431.                          * to nill or problem is fixed this code must remain enabled for all systems.
  432.                          */
  433.                         s = strrchr(filename, ‘\‘);
  434. if ((tmp = strrchr(filename, ‘/‘)) > s) {
  435. s = tmp;
  436. }
  437. #ifdef PHP_WIN32
  438. if (PG(magic_quotes_gpc)) {
  439. s = s ? s : filename;
  440. tmp = strrchr(s, ‘‘‘);
  441.                                 s = tmp > s ? tmp : s;
  442.                                 tmp = strrchr(s, ‘"‘);
  443.                                 s = tmp > s ? tmp : s;
  444.                         }
  445. #endif
  446.  
  447. #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
  448. filedone:
  449. #endif
  450.  
  451.                         if (!is_anonymous) {
  452.                                 if (s && s > filename) {
  453.                                         safe_php_register_variable(lbuf, s+1, strlen(s+1), NULL, 0 TSRMLS_CC);
  454.                                 } else {
  455.                                         safe_php_register_variable(lbuf, filename, strlen(filename), NULL, 0 TSRMLS_CC);
  456.                                 }
  457.                         }
  458.  
  459.                         /* Add $foo[name] */
  460.                         if (is_arr_upload) {
  461.                                 snprintf(lbuf, llen, "%s[name][%s]", abuf, array_index);
  462.                         } else {
  463.                                 snprintf(lbuf, llen, "%s[name]", param);
  464.                         }
  465.                         if (s && s > filename) {
  466.                                 register_http_post_files_variable(lbuf, s+1, http_post_files, 0 TSRMLS_CC);
  467.                         } else {
  468.                                 register_http_post_files_variable(lbuf, filename, http_post_files, 0 TSRMLS_CC);
  469.                         }
  470.                         efree(filename);
  471.                         s = NULL;
  472.  
  473.                         /* Possible Content-Type: */
  474.                         if (cancel_upload || !(cd = php_mime_get_hdr_value(header, "Content-Type"))) {
  475.                                 cd = "";
  476.                         } else {
  477.                                 /* fix for Opera 6.01 */
  478.                                 s = strchr(cd, ‘;‘);
  479.                                 if (s != NULL) {
  480.                                         *s = ‘‘;
  481.                                 }
  482.                         }
  483.  
  484.                         /* Add $foo_type */
  485.                         if (is_arr_upload) {
  486.                                 snprintf(lbuf, llen, "%s_type[%s]", abuf, array_index);
  487.                         } else {
  488.                                 snprintf(lbuf, llen, "%s_type", param);
  489.                         }
  490.                         if (!is_anonymous) {
  491.                                 safe_php_register_variable(lbuf, cd, strlen(cd), NULL, 0 TSRMLS_CC);
  492.                         }
  493.  
  494.                         /* Add $foo[type] */
  495.                         if (is_arr_upload) {
  496.                                 snprintf(lbuf, llen, "%s[type][%s]", abuf, array_index);
  497.                         } else {
  498.                                 snprintf(lbuf, llen, "%s[type]", param);
  499.                         }
  500.                         register_http_post_files_variable(lbuf, cd, http_post_files, 0 TSRMLS_CC);
  501.  
  502.                         /* Restore Content-Type Header */
  503.                         if (s != NULL) {
  504.                                 *s = ‘;‘;
  505.                         }
  506.                         s = "";
  507.  
  508.                         /* Initialize variables */
  509.                         add_protected_variable(param TSRMLS_CC);
  510.  
  511.                         magic_quotes_gpc = PG(magic_quotes_gpc);
  512.                         PG(magic_quotes_gpc) = 0;
  513.                         /* if param is of form xxx[.*] this will cut it to xxx */
  514.                         if (!is_anonymous) {
  515.                                 safe_php_register_variable(param, temp_filename, strlen(temp_filename), NULL, 1 TSRMLS_CC);
  516.                         }
  517.  
  518.                         /* Add $foo[tmp_name] */
  519.                         if (is_arr_upload) {
  520.                                 snprintf(lbuf, llen, "%s[tmp_name][%s]", abuf, array_index);
  521.                         } else {
  522.                                 snprintf(lbuf, llen, "%s[tmp_name]", param);
  523.                         }
  524.                         add_protected_variable(lbuf TSRMLS_CC);
  525.                         register_http_post_files_variable(lbuf, temp_filename, http_post_files, 1 TSRMLS_CC);
  526.  
  527.                         PG(magic_quotes_gpc) = magic_quotes_gpc;
  528.  
  529.                         {
  530.                                 zval file_size, error_type;
  531.  
  532.                                 error_type.value.lval = cancel_upload;
  533.                                 error_type.type = IS_LONG;
  534.  
  535.                                 /* Add $foo[error] */
  536.                                 if (cancel_upload) {
  537.                                         file_size.value.lval = 0;
  538.                                         file_size.type = IS_LONG;
  539.                                 } else {
  540.                                         file_size.value.lval = total_bytes;
  541.                                         file_size.type = IS_LONG;
  542.                                 }
  543.  
  544.                                 if (is_arr_upload) {
  545.                                         snprintf(lbuf, llen, "%s[error][%s]", abuf, array_index);
  546.                                 } else {
  547.                                         snprintf(lbuf, llen, "%s[error]", param);
  548.                                 }
  549.                                 register_http_post_files_variable_ex(lbuf, &error_type, http_post_files, 0 TSRMLS_CC);
  550.  
  551.                                 /* Add $foo_size */
  552.                                 if (is_arr_upload) {
  553.                                         snprintf(lbuf, llen, "%s_size[%s]", abuf, array_index);
  554.                                 } else {
  555.                                         snprintf(lbuf, llen, "%s_size", param);
  556.                                 }
  557.                                 if (!is_anonymous) {
  558.                                         safe_php_register_variable_ex(lbuf, &file_size, NULL, 0 TSRMLS_CC);
  559.                                 }
  560.  
  561.                                 /* Add $foo[size] */
  562.                                 if (is_arr_upload) {
  563.                                         snprintf(lbuf, llen, "%s[size][%s]", abuf, array_index);
  564.                                 } else {
  565.                                         snprintf(lbuf, llen, "%s[size]", param);
  566.                                 }
  567.                                 register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, 0 TSRMLS_CC);
  568.                         }
  569.                         efree(param);
  570.                 }
  571.         }
  572. fileupload_done:
  573.         if (php_rfc1867_callback != NULL) {
  574.                 multipart_event_end event_end;
  575.  
  576.                 event_end.post_bytes_processed = SG(read_post_bytes);
  577.                 php_rfc1867_callback(MULTIPART_EVENT_END, &event_end, &event_extra_data TSRMLS_CC);
  578.         }
  579.  
  580.         SAFE_RETURN;
  581. }

 

 

上传文件,提示文件不存在的解决方法,布布扣,bubuko.com

上传文件,提示文件不存在的解决方法

原文:http://www.cnblogs.com/taek/p/3812649.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!