Recommend this page to a friend! |
PHP Classes blog | > | File upload progress ... | > | All threads | > | Patch for 4.4.3 | > | (Un) Subscribe thread alerts |
|
1 - 10 | 11 - 14 |
Guillermo - 2007-07-16 14:11:55 - In reply to message 10 from Manuel Lemos
Ok, I have this patch for php.4.4.7. I apply the same and compile php. Then install the uploadprogress extension. But when I add the line "extension=uploadprogress.so" in the php.ini, I see this:
PHP Warning: Unknown(): (null): Unable to initialize module Module compiled with module API=20060613, debug=0, thread-safety=0 PHP compiled with module API=20020429, debug=0, thread-safety=0 These options need to match in Unknown on line 0 I don't know, may be there is somethingo wrong with the patch. Patch: diff -Paur php-4.4.7-orig/main/rfc1867.c php-4.4.7/main/rfc1867.c --- php-4.4.7-orig/main/rfc1867.c 2007-04-12 21:42:48.000000000 -0300 +++ php-4.4.7/main/rfc1867.c 2007-07-10 12:29:16.000000000 -0300 @@ -34,6 +34,8 @@ #undef DEBUG_FILE_UPLOAD +PHPAPI int (*php_rfc1867_callback)(unsigned int event, void *event_data, void **extra TSRMLS_DC) = NULL; + #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) #include "ext/mbstring/mbstring.h" @@ -128,6 +130,7 @@ #define UPLOAD_ERROR_D 4 /* No file uploaded */ #define UPLOAD_ERROR_E 6 /* Missing /tmp or similar directory */ #define UPLOAD_ERROR_F 7 /* Failed to write file to disk */ +#define UPLOAD_ERROR_X 8 /* File upload stopped by extension */ void php_rfc1867_register_constants(TSRMLS_D) { @@ -138,6 +141,7 @@ REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_NO_FILE", UPLOAD_ERROR_D, CONST_CS | CONST_PERSISTENT); REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_NO_TMP_DIR", UPLOAD_ERROR_E, CONST_CS | CONST_PERSISTENT); REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_CANT_WRITE", UPLOAD_ERROR_F, CONST_CS | CONST_PERSISTENT); + REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_EXTENSION", UPLOAD_ERROR_X, CONST_CS | CONST_PERSISTENT); } static void normalize_protected_variable(char *varname TSRMLS_DC) @@ -787,6 +791,7 @@ zval *array_ptr = (zval *) arg; int fd=-1; zend_llist header; + void *event_extra_data = NULL; if (SG(request_info).content_length > SG(post_max_size)) { 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)); @@ -845,16 +850,26 @@ #endif zend_llist_init(&header, sizeof(mime_header_entry), (llist_dtor_func_t) php_free_hdr_entry, 0); + if (php_rfc1867_callback != NULL) { + multipart_event_start event_start; + + event_start.content_length = SG(request_info).content_length; + if (php_rfc1867_callback(MULTIPART_EVENT_START, &event_start, &event_extra_data TSRMLS_CC) == FAILURE) { + goto fileupload_done; + } + } + while (!multipart_buffer_eof(mbuff TSRMLS_CC)) { char buff[FILLUNIT]; char *cd=NULL,*param=NULL,*filename=NULL, *tmp=NULL; - int blen=0, wlen=0; + size_t blen=0, wlen=0; + off_t offset; zend_llist_clean(&header); if (!multipart_buffer_headers(mbuff, &header TSRMLS_CC)) { - SAFE_RETURN; + goto fileupload_done; } if ((cd = php_mime_get_hdr_value(header, "Content-Disposition"))) { @@ -898,11 +913,23 @@ if (!filename && param) { unsigned int value_len; char *value = multipart_buffer_read_body(mbuff, &value_len TSRMLS_CC); + unsigned int new_val_len; /* Dummy variable */ if (!value) { value = estrdup(""); } + if (php_rfc1867_callback != NULL) { + multipart_event_formdata event_formdata; + + event_formdata.post_bytes_processed = SG(read_post_bytes); + event_formdata.name = param; + event_formdata.value = &value; + event_formdata.length = value_len; + event_formdata.newlength = NULL; + php_rfc1867_callback(MULTIPART_EVENT_FORMDATA, &event_formdata, &event_extra_data TSRMLS_CC); + } + #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) if (php_mb_encoding_translation(TSRMLS_C)) { php_mb_gpc_stack_variable(param, value, &val_list, &len_list, @@ -924,22 +951,13 @@ /* If file_uploads=off, skip the file part */ if (!PG(file_uploads)) { - if (filename) { - efree(filename); - } - if (param) { - efree(param); - } - continue; + skip_upload = 1; } /* Return with an error if the posted data is garbled */ - if (!param) { + if (!param && !filename) { sapi_module.sapi_error(E_WARNING, "File Upload Mime headers garbled"); - if (filename) { - efree(filename); - } - SAFE_RETURN; + goto fileupload_done; } /* New Rule: never repair potential malicious user input */ @@ -975,6 +993,29 @@ cancel_upload = UPLOAD_ERROR_E; } } + + if (!skip_upload && php_rfc1867_callback != NULL) { + multipart_event_file_start event_file_start; + + event_file_start.post_bytes_processed = SG(read_post_bytes); + event_file_start.name = param; + event_file_start.filename = &filename; + if (php_rfc1867_callback(MULTIPART_EVENT_FILE_START, &event_file_start, &event_extra_data TSRMLS_CC) == FAILURE) { + if (temp_filename) { + if (cancel_upload != UPLOAD_ERROR_E) { /* file creation failed */ + close(fd); + unlink(temp_filename); + } + efree(temp_filename); + } + temp_filename=""; + efree(param); + efree(filename); + continue; + } + } + + if (skip_upload) { efree(param); efree(filename); @@ -988,9 +1029,25 @@ cancel_upload = UPLOAD_ERROR_D; } + offset = 0; end = 0; while (!cancel_upload && (blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end TSRMLS_CC))) { + if (php_rfc1867_callback != NULL) { + multipart_event_file_data event_file_data; + + event_file_data.post_bytes_processed = SG(read_post_bytes); + event_file_data.offset = offset; + event_file_data.data = buff; + event_file_data.length = blen; + event_file_data.newlength = &blen; + if (php_rfc1867_callback(MULTIPART_EVENT_FILE_DATA, &event_file_data, &event_extra_data TSRMLS_CC) == FAILURE) { + cancel_upload = UPLOAD_ERROR_X; + continue; + } + } + + if (PG(upload_max_filesize) > 0 && total_bytes > PG(upload_max_filesize)) { sapi_module.sapi_error(E_WARNING, "upload_max_filesize of %ld bytes exceeded - file [%s=%s] not saved", PG(upload_max_filesize), param, filename); cancel_upload = UPLOAD_ERROR_A; @@ -1006,6 +1063,8 @@ } else { total_bytes += wlen; } + + offset += wlen; } } if (fd!=-1) { @@ -1026,6 +1085,17 @@ } #endif + if (php_rfc1867_callback != NULL) { + multipart_event_file_end event_file_end; + + event_file_end.post_bytes_processed = SG(read_post_bytes); + event_file_end.temp_filename = temp_filename; + event_file_end.cancel_upload = cancel_upload; + if (php_rfc1867_callback(MULTIPART_EVENT_FILE_END, &event_file_end, &event_extra_data TSRMLS_CC) == FAILURE) { + cancel_upload = UPLOAD_ERROR_X; + } + } + if (cancel_upload) { if (temp_filename) { if (cancel_upload != UPLOAD_ERROR_E) { /* file creation failed */ @@ -1217,7 +1287,14 @@ efree(param); } } - +fileupload_done: + if (php_rfc1867_callback != NULL) { + multipart_event_end event_end; + + event_end.post_bytes_processed = SG(read_post_bytes); + php_rfc1867_callback(MULTIPART_EVENT_END, &event_end, &event_extra_data TSRMLS_CC); + } + SAFE_RETURN; } diff -Paur php-4.4.7-orig/main/rfc1867.h php-4.4.7/main/rfc1867.h --- php-4.4.7-orig/main/rfc1867.h 2002-07-11 22:49:58.000000000 -0300 +++ php-4.4.7/main/rfc1867.h 2007-07-10 12:28:41.000000000 -0300 @@ -1,13 +1,76 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2006 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: | + +----------------------------------------------------------------------+ +*/ + +/* $Id: rfc1867.h,v 1.13.2.1.2.2 2006/07/26 13:22:06 tony2001 Exp $ */ + #ifndef RFC1867_H #define RFC1867_H #include "SAPI.h" #define MULTIPART_CONTENT_TYPE "multipart/form-data" +#define MULTIPART_EVENT_START 0 +#define MULTIPART_EVENT_FORMDATA 1 +#define MULTIPART_EVENT_FILE_START 2 +#define MULTIPART_EVENT_FILE_DATA 3 +#define MULTIPART_EVENT_FILE_END 4 +#define MULTIPART_EVENT_END 5 + +typedef struct _multipart_event_start { + size_t content_length; +} multipart_event_start; + +typedef struct _multipart_event_formdata { + size_t post_bytes_processed; + char *name; + char **value; + size_t length; + size_t *newlength; +} multipart_event_formdata; + +typedef struct _multipart_event_file_start { + size_t post_bytes_processed; + char *name; + char **filename; +} multipart_event_file_start; + +typedef struct _multipart_event_file_data { + size_t post_bytes_processed; + off_t offset; + char *data; + size_t length; + size_t *newlength; +} multipart_event_file_data; + +typedef struct _multipart_event_file_end { + size_t post_bytes_processed; + char *temp_filename; + int cancel_upload; +} multipart_event_file_end; + +typedef struct _multipart_event_end { + size_t post_bytes_processed; +} multipart_event_end; SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler); void destroy_uploaded_files_hash(TSRMLS_D); void php_rfc1867_register_constants(TSRMLS_D); +extern PHPAPI int (*php_rfc1867_callback)(unsigned int event, void *event_data, void **extra TSRMLS_DC); #endif /* RFC1867_H */
Guillermo - 2007-07-16 16:56:34 - In reply to message 11 from Guillermo
Ok finally, I have uploadprogress support in php 4.4.7. The patch is Ok, I have a path error in the php.ini.
:) uploadprogress support enabled Version 0.3.0-beta
Manuel Lemos - 2007-07-16 21:31:28 - In reply to message 12 from Guillermo
Great, if you do not mind I will publish it with the other version patches in the forms class distribution. I will give you credit, of course.
Guillermo - 2007-07-16 23:50:28 - In reply to message 13 from Manuel Lemos
Sure, go ahead and thanks for your help. About the patch, the credit is not all mine but it's OK. :)
|
1 - 10 | 11 - 14 |
info at phpclasses dot org
.