Re: [PHP-DEV] Upload Progress Meter Patch

2005-07-22 Thread Doru Petrescu
has anyone figure it out if it was rejected or just forgotten ?
and if it was rejected, what was the reason ?

the only valid reason I seen so far was that you can do this using
something else (perl, or an apache module, or even something more
exotic). but, this also apply to php itself ... I can write dinamic web
pages using something else too ... like perl, jsp, etc. are you trying
to give me a reason NOT TO USE PHP ?!? 

the patch I am proposing will only provide a hook mechanism in the
upload processing function. nothing more. it only adds few lines to
rfc1867.c alowing for a loadable module to hook into.

and if someone thinks the patch is TOO BIG, i'm sure we can make it even
smaller and less intrusive.

I think that the automatic processing of uploads with no way of
disabling it (and it manually) is a shortcoming of PHP in the first
place. the fact that there is no configuration, no option to enable or
disable it is a negative point of the design.


I cant see any disadvantage of having that hook in place, and so far
nobody gave me any good reason not to have it. 

and please, at least take a look over the patch before rejecting it ?
and give me a valid reason for doing so.

thank you for your time,
Doru Petrescu


On Wed, 2005-03-23 at 19:15, Zeev Suraski wrote:
> Can you point us to the thread?  I can't recall seeing it rejected, and I 
> can't find the thread either...
> 
> Zeev
> 
> At 15:37 23/03/2005, Derick Rethans wrote:
> >On Wed, 23 Mar 2005, Robert wrote:
> >
> > > >This was already considered and rejected. No need to start the discussion
> > > >again.
> > > >
> > > All I saw is that the discussion stopped, not that it was rejected.
> >
> >Then you should look further - it was rejected.
> >
> >Derick
> >
> >--
> >Derick Rethans
> >http://derickrethans.nl | http://ez.no | http://xdebug.org
> >
> >--
> >PHP Internals - PHP Runtime Development Mailing List
> >To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] upload progress meter - new version v4.1 available for php 4.3.10 and 5.0.3

2005-01-31 Thread Doru Petrescu
ah ... I forgot to mention:
  http://pdoru.from.ro 

is the address to download the files.

D.

On Mon, 2005-01-31 at 17:46, Doru Petrescu wrote:
> Hi,
> 
> Just wanted to let you all know that a new version is available to work
> with PHP 4.3.10 and 5.0.3
> 
> 
> As you probably already know, the upload progress meter is:
> 
> A way to track the progress of a file that is uploaded to the web
> server WHILE the file is uploaded, and with some scripts and HTML code
> display a nice progress bar to the user that is uploading the file.
> 
> 
> NEW in this version:
> 1. updated patches for new php versions 4.3.10 and 5.0.3
> 2. fixed one bug in the php extension to actualy close the tmp file when
> done reading from it.
> (file upload_progress_meter.c function file_php_get_info() )
> 
> 
> Best regards,
> Doru Petrescu

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] upload progress meter - new version v4.1 available for php 4.3.10 and 5.0.3

2005-01-31 Thread Doru Petrescu

Hi,

Just wanted to let you all know that a new version is available to work
with PHP 4.3.10 and 5.0.3


As you probably already know, the upload progress meter is:

A way to track the progress of a file that is uploaded to the web
server WHILE the file is uploaded, and with some scripts and HTML code
display a nice progress bar to the user that is uploading the file.


NEW in this version:
1. updated patches for new php versions 4.3.10 and 5.0.3
2. fixed one bug in the php extension to actualy close the tmp file when
done reading from it.
(file upload_progress_meter.c function file_php_get_info() )


Best regards,
Doru Petrescu

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] [PATCH] sapi apache2 uninitialized content-length value

2004-02-05 Thread Doru Petrescu
I resend it. it seems that my mailer corrupted the attachement.

-- 


Best regards,
Doru Petrescu
Senior Software Engineer
Astral Telecom Bucuresti
   
 



--- Begin Message ---

   Hi,

   While playing with the upload progress meter I noticed that apache2
sapi implementation does not initialize the content-length sapi
variable. Apache 1.3 sapi does! and so does ALL OTHER interfaces. A
quick grep into the sources will reveal that only apache2handler and
apache2filter does not initialize this. Is there a reason for this ? Or
is just something that sliped ?

   I wrote a patch to fix this. see attached. tested and it works with
no problem and correctly reports the content-length.
   It is very simple and straight forward. copy/paste from apache 1.3
interface. now, I just wish nobody will upload anything over 2GB -
integer overflow will doom the upload.

   
   
-- 


Best regards,
Doru Petrescu
Senior Software Engineer
Astral Telecom Bucuresti
   
 



diff -rubB orig/php-4.3.4/sapi/apache2filter/sapi_apache2.c php-4.3.4/sapi/apache2filter/sapi_apache2.c
--- orig/php-4.3.4/sapi/apache2filter/sapi_apache2.c	2003-08-03 22:31:13.0 +0300
+++ php-4.3.4/sapi/apache2filter/sapi_apache2.c	2003-11-19 19:34:02.0 +0200
@@ -376,6 +376,7 @@
 static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx TSRMLS_DC)
 {
 	char *content_type;
+	char *content_length;
 	const char *auth;
 	
 	PG(during_request_startup) = 0;
@@ -393,6 +394,10 @@
 	SG(request_info).post_data = ctx->post_data;
 	SG(request_info).post_data_length = ctx->post_len;
 	efree(content_type);
+
+	content_length = (char *) apr_table_get(f->r->headers_in, "Content-Length");
+	SG(request_info).content_length = (content_length ? atoi(content_length) : 0);
+	
 	apr_table_unset(f->r->headers_out, "Content-Length");
 	apr_table_unset(f->r->headers_out, "Last-Modified");
 	apr_table_unset(f->r->headers_out, "Expires");
diff -rubB orig/php-4.3.4/sapi/apache2handler/sapi_apache2.c php-4.3.4/sapi/apache2handler/sapi_apache2.c
--- orig/php-4.3.4/sapi/apache2handler/sapi_apache2.c	2003-10-02 06:24:43.0 +0300
+++ php-4.3.4/sapi/apache2handler/sapi_apache2.c	2003-11-19 19:34:52.0 +0200
@@ -414,6 +414,7 @@
 static void php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC)
 {
 	char *content_type;
+	char *content_length;
 	const char *auth;
 
 	SG(sapi_headers).http_response_code = !r->status ? HTTP_OK : r->status;
@@ -428,6 +429,9 @@
 	ap_set_content_type(r, apr_pstrdup(r->pool, content_type));
 	efree(content_type);
 
+	content_length = (char *) apr_table_get(f->r->headers_in, "Content-Length");
+	SG(request_info).content_length = (content_length ? atoi(content_length) : 0);
+
 	apr_table_unset(r->headers_out, "Content-Length");
 	apr_table_unset(r->headers_out, "Last-Modified");
 	apr_table_unset(r->headers_out, "Expires");

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php--- End Message ---
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] apache2 sapi uninitialized content-length value

2004-02-05 Thread Doru Petrescu


On Thu, 2004-02-05 at 14:27, Jani Taskinen wrote: 
> I don't remember seeing any patch..nor do I see one now..
> And what exactly is the problem you see that the patch fixes?


Here it is again ...
Is there a problem with the archive from 20 Nov 2003 ?!?!?



> On Thu, 5 Feb 2004, Doru Petrescu wrote:
> 
> >
> >
> >Hi,
> >
> >some time ago I sent a patch to fix this uninitialized variable in the
> >apache2 sapi code. all other SAPIs DO initialize it, so I figured out it
> >is something that should be corrected. 
> >
> >I see neither php-5.0.0B3 nor php-4.3.5RC2 implement this.
> >
> >Can someone comment on this ? Was my 2 line patch incorrectly wrote ?
> >Maybe it did not apply ? Maybe it is wrong to initialize that variable ?
> >but then why other SAPIs initialize it ? are them wrong ? is there a
> >hidden security problem that I did not see ?
> >
> >My original email was sent on 20 Nov 2003, original subj was "[PHP-DEV]
> >[PATCH] sapi apache2 uninitialized content-length value"
> >
> >
> >
--- Begin Message ---
This is a MIME-formatted message.  If you see this text it means that your
E-mail software does not support MIME-formatted messages.

--=3D3D3D_dial-30688-1069326812-0001-2
Content-Type: text/plain; charset=3D3D3Diso-8859-1
Content-Transfer-Encoding: 8bit


   Hi,

   While playing with the upload progress meter I noticed that apache2
sapi implementation does not initialize the content-length sapi
variable. Apache 1.3 sapi does! and so does ALL OTHER interfaces. A
quick grep into the sources will reveal that only apache2handler and
apache2filter does not initialize this. Is there a reason for this ? Or
is just something that sliped ?

   I wrote a patch to fix this. see attached. tested and it works with
no problem and correctly reports the content-length.
   It is very simple and straight forward. copy/paste from apache 1.3
interface. now, I just wish nobody will upload anything over 2GB -
integer overflow will doom the upload.

  =3D3D20
  =3D3D20
--=3D3D20


Best regards,
Doru Petrescu
Senior Software Engineer
Astral Telecom Bucuresti
   =
=3D
=3D3D
=3D3D20




--=3D3D3D_dial-30688-1069326812-0001-2
Content-Type: text/x-patch; name=3D3D3D"patch.sapi_apache2_content_length.t=
xt=3D
";=3D3D
 charset=3D3D3Diso-8859-1
Content-Disposition: attachment; filename=3D3D3Dpatch.sapi_apache2_content_=
le=3D
ng=3D3D
th.txt
Content-Transfer-Encoding: 8bit

diff -rubB orig/php-4.3.4/sapi/apache2filter/sapi_apache2.c php-4.3.4/sapi/=
=3D
=3D3D
apache2filter/sapi_apache2.c
--- orig/php-4.3.4/sapi/apache2filter/sapi_apache2.c2003-08-03 22:31:13.00=
=3D
=3D3D
000 +0300
+++ php-4.3.4/sapi/apache2filter/sapi_apache2.c 2003-11-19 19:34:02.000=
=3D
=3D3D
00 +0200
@@ -376,6 +376,7 @@
 static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx TSRMLS=
=3D
=3D3D
_DC)
 {
char *content_type;
+   char *content_length;
const char *auth;
 =3D3D09
PG(during_request_startup) =3D3D3D 0;
@@ -393,6 +394,10 @@
SG(request_info).post_data =3D3D3D ctx->post_data;
SG(request_info).post_data_length =3D3D3D ctx->post_len;
efree(content_type);
+
+   content_length =3D3D3D (char *) apr_table_get(f->r->headers_in, "Content-=
Le=3D
ng=3D3D
th");
+   SG(request_info).content_length =3D3D3D (content_length ? atoi(content_le=
ng=3D
th=3D3D
) : 0);
+=3D3D09
apr_table_unset(f->r->headers_out, "Content-Length");
apr_table_unset(f->r->headers_out, "Last-Modified");
apr_table_unset(f->r->headers_out, "Expires");
diff -rubB orig/php-4.3.4/sapi/apache2handler/sapi_apache2.c php-4.3.4/sapi=
=3D
=3D3D
/apache2handler/sapi_apache2.c
--- orig/php-4.3.4/sapi/apache2handler/sapi_apache2.c   2003-10-02 06:24:43.0=
=3D
=3D3D
 +0300
+++ php-4.3.4/sapi/apache2handler/sapi_apache2.c2003-11-19 19:34:52.00=
=3D
=3D3D
000 +0200
@@ -414,6 +414,7 @@
 static void php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS=
=3D
=3D3D
_DC)
 {
char *content_type;
+   char *content_length;
const char *auth;
=3D3D20
SG(sapi_headers).http_response_code =3D3D3D !r->status ? HTTP_OK : r->sta=
tu=3D
s;
@@ -428,6 +429,9 @@
ap_set_content_type(r, apr_pstrdup(r->pool, content_type));
efree(content_type);
=3D3D20
+   content_length =3D3D3D (char *) apr_table_get(f->r->headers_in, "Content-=
Le=3D
ng=3D3D
th");
+   SG(request_info).content_length =3D3D3D (content_length ? atoi(content_le=
ng=3D
th=3D3D
) : 0);
+
apr_table_unset(r->headers_out, "Content-Length");
apr_table_unset(r->headers_out, "Last-Modi

[PHP-DEV] apache2 sapi uninitialized content-length value

2004-02-05 Thread Doru Petrescu


Hi,

some time ago I sent a patch to fix this uninitialized variable in the
apache2 sapi code. all other SAPIs DO initialize it, so I figured out it
is something that should be corrected. 

I see neither php-5.0.0B3 nor php-4.3.5RC2 implement this.

Can someone comment on this ? Was my 2 line patch incorrectly wrote ?
Maybe it did not apply ? Maybe it is wrong to initialize that variable ?
but then why other SAPIs initialize it ? are them wrong ? is there a
hidden security problem that I did not see ?

My original email was sent on 20 Nov 2003, original subj was "[PHP-DEV]
[PATCH] sapi apache2 uninitialized content-length value"


-- 


Best regards,
Doru Theodor Petrescu
Senior Software Engineer
Astral Telecom Bucuresti
   
 

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] raw post data

2003-11-21 Thread Doru Petrescu
On Fri, 2003-11-21 at 05:04, Hartmut Holzgraefe wrote:
> Andi Gutmans wrote:
> > Any chance we can make the necessary changes to support an upload 
> > progress bar? I came accross this web site but I'm not quite sure if 
> > always populating RAW_POST_DATA is enough.
> > http://www.raditha.com/php/progress.php
> 
> RAW_POST_DATA won't help at all here as PHP user code execution
> won't start until all incoming request data had been read and
> stored in the special variable
> 
> their "change the from content type to something unknown" might
> work if they'd use the php://input stream instead though ...
> 
> -- 
> Hartmut Holzgraefe  <[EMAIL PROTECTED]>


I don't think this will help either as PHP always read the entire
content-length BEFORE even loading the actual php script. As long as you
using php as a web server module you cannot escape this.

if you need to run something while the data is received we need to
change the way php works. the way I see things is to put hook in the 
function that read the data from the client. This will allow execution
of code while post data is received.

and it happens that such feature was already suggested by me together
with a patch yesterday ... see my email 'upload-progress-tracking'



-- 


Best regards,
Doru Petrescu
Senior Software Engineer
Astral Telecom Bucuresti
   
 

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [PATCH] sapi apache2 uninitialized content-length value

2003-11-20 Thread Doru Petrescu
you missed the point. it is probably zero like it is now, the point was
to put the right value there, not some garbage.

and of course I DO NEED THAT VALUE at some point in time, and I see no
use of having garbage or a wrong value there. also what stroke me is
that all other sapi modules were properly initializing this value ...


Doru Petrescu


On Thu, 2003-11-20 at 16:31, Ilia Alshanetsky wrote:
> Why not simply do SG(request_info).content_length = 0; ?
> 
> Ilia

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] [PATCH] sapi apache2 uninitialized content-length value

2003-11-20 Thread Doru Petrescu

   Hi,

   While playing with the upload progress meter I noticed that apache2
sapi implementation does not initialize the content-length sapi
variable. Apache 1.3 sapi does! and so does ALL OTHER interfaces. A
quick grep into the sources will reveal that only apache2handler and
apache2filter does not initialize this. Is there a reason for this ? Or
is just something that sliped ?

   I wrote a patch to fix this. see attached. tested and it works with
no problem and correctly reports the content-length.
   It is very simple and straight forward. copy/paste from apache 1.3
interface. now, I just wish nobody will upload anything over 2GB -
integer overflow will doom the upload.

   
   
-- 


Best regards,
Doru Petrescu
Senior Software Engineer
Astral Telecom Bucuresti
   
 



diff -rubB orig/php-4.3.4/sapi/apache2filter/sapi_apache2.c php-4.3.4/sapi/apache2filter/sapi_apache2.c
--- orig/php-4.3.4/sapi/apache2filter/sapi_apache2.c	2003-08-03 22:31:13.0 +0300
+++ php-4.3.4/sapi/apache2filter/sapi_apache2.c	2003-11-19 19:34:02.0 +0200
@@ -376,6 +376,7 @@
 static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx TSRMLS_DC)
 {
 	char *content_type;
+	char *content_length;
 	const char *auth;
 	
 	PG(during_request_startup) = 0;
@@ -393,6 +394,10 @@
 	SG(request_info).post_data = ctx->post_data;
 	SG(request_info).post_data_length = ctx->post_len;
 	efree(content_type);
+
+	content_length = (char *) apr_table_get(f->r->headers_in, "Content-Length");
+	SG(request_info).content_length = (content_length ? atoi(content_length) : 0);
+	
 	apr_table_unset(f->r->headers_out, "Content-Length");
 	apr_table_unset(f->r->headers_out, "Last-Modified");
 	apr_table_unset(f->r->headers_out, "Expires");
diff -rubB orig/php-4.3.4/sapi/apache2handler/sapi_apache2.c php-4.3.4/sapi/apache2handler/sapi_apache2.c
--- orig/php-4.3.4/sapi/apache2handler/sapi_apache2.c	2003-10-02 06:24:43.0 +0300
+++ php-4.3.4/sapi/apache2handler/sapi_apache2.c	2003-11-19 19:34:52.0 +0200
@@ -414,6 +414,7 @@
 static void php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC)
 {
 	char *content_type;
+	char *content_length;
 	const char *auth;
 
 	SG(sapi_headers).http_response_code = !r->status ? HTTP_OK : r->status;
@@ -428,6 +429,9 @@
 	ap_set_content_type(r, apr_pstrdup(r->pool, content_type));
 	efree(content_type);
 
+	content_length = (char *) apr_table_get(f->r->headers_in, "Content-Length");
+	SG(request_info).content_length = (content_length ? atoi(content_length) : 0);
+
 	apr_table_unset(r->headers_out, "Content-Length");
 	apr_table_unset(r->headers_out, "Last-Modified");
 	apr_table_unset(r->headers_out, "Expires");

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-DEV] [PATCH] upload-progress-tracking

2003-11-20 Thread Doru Petrescu

   Hi,
   
 
   This is a patch that implements a hooking mechanism into the
rfc1867_post_handler() function that process post content of type
multipart/form-data, for example when uploading files. This will allow
execution of a callback routine while php reads and process the incoming data.
This happens before the actual script is loaded and executed. This will make
possible for an extension to register a callback, that will do something
interesting like an upload-progress-meter for the incoming uploads.
   
 
   This wishes to be a better approach to do U-P-M than my previous patch, that
was inserting ugly code directly into rfc1867_post_handler() function. This
new implementation provides separation of code, and a standard hooking
mechanism, whatever you need to do.
   
 
   This patch define a new configuration option 'upload_progress_tracking'
(default off). You will have to turn it ON, in order for U-P-M to work. This
is intended to reduce the number of wasted cpu cycles when this feature is not
needed. You should turn this on only for the directories/files that actually
need and use this.
   
 
   Security considerations: data received from client is checked for valid
characters and valid length before doing anything else with it.
  

   What can be done with this ? well... this was intended to be a way to do 
an upload progress meter, but you can do a lot of other things, even RUN PHP 
CODE while data is uploaded. I have a quick&dirt patch available if anyone want 
to play with ...

  
   See the attached README file for more technical details.
   BTW, patch is against php-4.3.4

--

Best regards,
Doru Petrescu
Senior Software Engineer
Astral Telecom Bucuresti
   
 



diff -rubB orig/php-4.3.4/main/main.c php-4.3.4/main/main.c
--- orig/php-4.3.4/main/main.c	2003-10-09 05:59:03.0 +0300
+++ php-4.3.4/main/main.c	2003-11-19 10:05:00.0 +0200
@@ -343,6 +343,7 @@
 	STD_PHP_INI_ENTRY("upload_max_filesize",	"2M",		PHP_INI_SYSTEM|PHP_INI_PERDIR,		OnUpdateInt,			upload_max_filesize,	php_core_globals,	core_globals)
 	STD_PHP_INI_ENTRY("post_max_size",			"8M",		PHP_INI_SYSTEM|PHP_INI_PERDIR,		OnUpdateInt,			post_max_size,			sapi_globals_struct,sapi_globals)
 	STD_PHP_INI_ENTRY("upload_tmp_dir",			NULL,		PHP_INI_SYSTEM,		OnUpdateStringUnempty,	upload_tmp_dir,			php_core_globals,	core_globals)
+	STD_PHP_INI_ENTRY("upload_progress_tracking",		"0",		PHP_INI_ALL,		OnUpdateBool,			upload_progress_tracking,		php_core_globals,   core_globals)
 
 	STD_PHP_INI_ENTRY("user_dir",NULL,		PHP_INI_SYSTEM,		OnUpdateString,			user_dir,php_core_globals,	core_globals)
 	STD_PHP_INI_ENTRY("variables_order",		NULL,		PHP_INI_ALL,		OnUpdateStringUnempty,	variables_order,		php_core_globals,	core_globals)
diff -rubB orig/php-4.3.4/main/php_globals.h php-4.3.4/main/php_globals.h
--- orig/php-4.3.4/main/php_globals.h	2003-05-18 13:22:16.0 +0300
+++ php-4.3.4/main/php_globals.h	2003-11-19 09:19:58.0 +0200
@@ -133,6 +133,7 @@
 	zend_bool modules_activated;
 
 	zend_bool file_uploads;
+	zend_bool upload_progress_tracking;
 
 	zend_bool during_request_startup;
 
diff -rubB orig/php-4.3.4/main/rfc1867.c php-4.3.4/main/rfc1867.c
--- orig/php-4.3.4/main/rfc1867.c	2003-10-26 09:47:24.0 +0200
+++ php-4.3.4/main/rfc1867.c	2003-11-20 09:37:30.0 +0200
@@ -61,6 +61,104 @@
 #define UPLOAD_ERROR_C3  /* Partially uploaded */
 #define UPLOAD_ERROR_D4  /* No file uploaded */
 
+
+
+/* Defines for upload progress tracking callback */
+#define UPLOAD_UPDATE0
+#define UPLOAD_DONE -1
+#define UPLOAD_GOT_A_NEW_FILE   +1
+
+#define UPLOAD_PROGRESS_UPDATE( progress, why )			\
+	if (upload_progress_active > 1) { 			\
+		upload_progress_callback( progress,		\
+SG(read_post_bytes), SG(request_info).content_length, why );	\
+	}
+
+int upload_progress_init( void**, char*);
+int upload_progress_register_callback( void* );
+void (*upload_progress_callback)( void*, int, int, int) = NULL;
+
+/*
+NOTES: 
+
+prototype for the callback:
+void upload_progress_callback( void *pointer, int read_bytes, int total_bytes, int what_happened )
+
+   
+1. first time call, to initialize: 
+upload_progress_callback( &tmp_pointer, 0, total, 0 )
+	tmp_pointer is an INPUT/OUTPUT parameter!
+	on INPUT: tmp_pointer = (cha

[PHP-DEV] new upload-meter patch for PHP 4.3.32

2003-09-09 Thread Doru Petrescu
Hi everybody,

Here is an updated patch for PHP 4.3.3 to enable the
upload-progress-meter I wrote some time ago.

For more details, and a live demo, please visit: http://pdoru.from.ro/

Best regards,
Doru Petrescu
Senior Software Engineer
Astral Telecom Bucuresti

diff -ruBb orig/php-4.3.3/main/main.c php-4.3.3/main/main.c
--- orig/php-4.3.3/main/main.c	2003-08-22 23:02:11.0 +0300
+++ php-4.3.3/main/main.c	2003-09-09 12:46:11.0 +0300
@@ -343,6 +343,8 @@
 	STD_PHP_INI_ENTRY("upload_max_filesize",	"2M",		PHP_INI_SYSTEM|PHP_INI_PERDIR,		OnUpdateInt,			upload_max_filesize,	php_core_globals,	core_globals)
 	STD_PHP_INI_ENTRY("post_max_size",			"8M",		PHP_INI_SYSTEM|PHP_INI_PERDIR,		OnUpdateInt,			post_max_size,			sapi_globals_struct,sapi_globals)
 	STD_PHP_INI_ENTRY("upload_tmp_dir",			NULL,		PHP_INI_SYSTEM,		OnUpdateStringUnempty,	upload_tmp_dir,			php_core_globals,	core_globals)
+ 	STD_PHP_INI_ENTRY("upload_metter",			"0",		PHP_INI_ALL,		OnUpdateBool,			upload_metter,			php_core_globals,	core_globals)
+ 	STD_PHP_INI_ENTRY("upload_metter_dir",			NULL,		PHP_INI_ALL,		OnUpdateStringUnempty,		upload_metter_dir,		php_core_globals,	core_globals)
 
 	STD_PHP_INI_ENTRY("user_dir",NULL,		PHP_INI_SYSTEM,		OnUpdateString,			user_dir,php_core_globals,	core_globals)
 	STD_PHP_INI_ENTRY("variables_order",		NULL,		PHP_INI_ALL,		OnUpdateStringUnempty,	variables_order,		php_core_globals,	core_globals)
diff -ruBb orig/php-4.3.3/main/php_globals.h php-4.3.3/main/php_globals.h
--- orig/php-4.3.3/main/php_globals.h	2003-05-18 13:22:16.0 +0300
+++ php-4.3.3/main/php_globals.h	2003-09-09 12:42:20.0 +0300
@@ -133,6 +133,8 @@
 	zend_bool modules_activated;
 
 	zend_bool file_uploads;
+	zend_bool upload_metter;
+	char * upload_metter_dir;
 
 	zend_bool during_request_startup;
 
diff -ruBb orig/php-4.3.3/main/rfc1867.c php-4.3.3/main/rfc1867.c
--- orig/php-4.3.3/main/rfc1867.c	2003-08-05 04:01:40.0 +0300
+++ php-4.3.3/main/rfc1867.c	2003-09-09 12:49:45.0 +0300
@@ -682,6 +684,81 @@
 	return out;
 }
 
+typedef struct _Xdata {
+   int time_start;
+   int time_last;
+   int speed_average;
+   int speed_last;
+   int bytes_uploaded;
+   int bytes_total;
+   int files_uploaded;
+   char progress[1024];
+} Xdata;
+
+static void update_progress_metter_file(Xdata *X)
+{
+   int eta,s;
+   FILE *F = VCWD_FOPEN(X->progress, "wb");
+
+   s   = X->speed_average; if (s < 1) s=1;
+   eta = (X->bytes_total - X->bytes_uploaded) / s;
+   
+   if (F) {
+   fprintf(F, "time_start=%d\ntime_last=%d\nspeed_average=%d\nspeed_last=%d\nbytes_uploaded=%d\nbytes_total=%d\nfiles_uploaded=%d\neta=%d\n",
+		   X->time_start, X->time_last, X->speed_average, X->speed_last, X->bytes_uploaded, X->bytes_total, X->files_uploaded, eta
+	  );
+   fclose(F);
+   }
+
+   sapi_module.sapi_error(E_NOTICE, "metter: read %d of %d", SG(read_post_bytes), SG(request_info).content_length );
+}
+
+static void update_progress_metter(Xdata *X, int read, int total) 
+{
+   int d,dt,dtx;
+   int bu;
+   int sp;
+
+
+   if (!X->time_start) {
+  X->time_start = X->time_last = time(NULL);
+
+  X->bytes_total= total;
+  X->bytes_uploaded = read;
+
+  X->speed_average  = X->speed_last = X->bytes_uploaded;
+
+  update_progress_metter_file(X);
+  return;
+   }
+
+   dt = time(NULL) - X->time_last;
+   d = read - X->bytes_uploaded;
+
+   if (dt < 1) {
+  if (read < total)
+ return; // avoid divide by zero
+  if (d < 1) 
+	 return;
+  dt = 1;
+   }
+
+
+
+   sp = d/dt;
+
+
+   X->bytes_uploaded = read;
+   X->time_last  = time(NULL);
+
+   dtx   = X->time_last - X->time_start; if (dtx < 1) dtx = 1;
+   X->speed_average  = X->bytes_uploaded / dtx;
+
+   X->speed_last = sp;
+
+   update_progress_metter_file(X);
+}
+
 
 /*
  * The combined READER/HANDLER
@@ -699,6 +776,9 @@
 	zval *array_ptr = (zval *) arg;
 	FILE *fp;
 	zend_llist header;
+ 	Xdata X;	
+ 	int progress_metter=0;
+ 
 #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
 	int str_len=0;
 #endif
@@ -708,6 +788,8 @@
 		return;
 	}
 
+	bzero(&X,sizeof(X));
+
 	/* Get the boundary */
 	boundary = strstr(content_type_dup, "boundary");
 	if (!boundary || !(boundary=strchr(boundary, '='))) {
@@ -762,6 +844,9 @@
 		zend_llist_clean(&header);
 
 		if (!multipart_buffer_headers(mbuff, &header TSRMLS_CC)) {
+
+
+			if (progress_metter) update_progress_metter( &X, SG(read_post_bytes), SG(request_info).content_length );
 			SAFE_RETURN;
 		}
 
@@ -823,6 +908,35 @@
 	max_file_size = atol(value);
 }
 
+
+
+if (!strcmp(param, "UPLOAD_METTER_ID") && PG(upload_metter) && PG(upl

[PHP-DEV] Re: [PATCH] upload progress metter

2003-06-14 Thread Doru Petrescu
there is a new patch available that fixes problems with apache2!

Also, I have noticed that sapi module for apache2handler and
apache2filter do not initialize SG(request_info).content_length during
request init. I had to add 3 lines of code to each one to initialize it.
looks like it works.

is this normal ? does the rest of sapi modules initialize this or not ?!?!

also there are some changes to the .php scripts too to fix some warnings.

visit http://pdoru.from.ro/ to get the new ones.


FYI, I am also thinking on a version that will use shared memory to store
upload progress information.

Best regards,
Doru Petrescu
Senior Software Engineer
Astral Telecom Bucuresti



---

diff -rubB orig/php-4.3.2/main/main.c php-4.3.2/main/main.c
--- orig/php-4.3.2/main/main.c  Thu May 22 01:54:38 2003
+++ php-4.3.2/main/main.c   Sun Jun 15 01:27:59 2003
@@ -345,7 +345,9 @@
STD_PHP_INI_BOOLEAN("file_uploads", "1",
PHP_INI_SYSTEM, OnUpdateBool,   file_uploads,  
 php_core_globals,   core_globals)
STD_PHP_INI_ENTRY("upload_max_filesize","2M",   
PHP_INI_SYSTEM|PHP_INI_PERDIR,  OnUpdateInt,
upload_max_filesize,php_core_globals,   core_globals)
STD_PHP_INI_ENTRY("post_max_size",  "8M",   
PHP_INI_SYSTEM|PHP_INI_PERDIR,  OnUpdateInt,post_max_size, 
 sapi_globals_struct,sapi_globals)
-   STD_PHP_INI_ENTRY("upload_tmp_dir", NULL,   
PHP_INI_SYSTEM, OnUpdateStringUnempty,  upload_tmp_dir, 
php_core_globals,   core_globals)
+   STD_PHP_INI_ENTRY("upload_tmp_dir", NULL,   
PHP_INI_ALL,OnUpdateStringUnempty,  upload_tmp_dir,
 php_core_globals,   core_globals)
+   STD_PHP_INI_ENTRY("upload_metter",  "0",
PHP_INI_ALL,OnUpdateBool,   upload_metter, 
 php_core_globals,   core_globals)
+   STD_PHP_INI_ENTRY("upload_metter_dir",  NULL,   
PHP_INI_ALL,OnUpdateStringUnempty,  upload_metter_dir, 
 php_core_globals,   core_globals)

STD_PHP_INI_ENTRY("user_dir",   NULL,   
PHP_INI_SYSTEM, OnUpdateString, user_dir,  
 php_core_globals,   core_globals)
STD_PHP_INI_ENTRY("variables_order",NULL,   PHP_INI_ALL,   
 OnUpdateStringUnempty,  variables_order,php_core_globals, 
  core_globals)
diff -rubB orig/php-4.3.2/main/php_globals.h php-4.3.2/main/php_globals.h
--- orig/php-4.3.2/main/php_globals.h   Sun May 18 13:22:16 2003
+++ php-4.3.2/main/php_globals.hSun Jun 15 01:27:59 2003
@@ -133,6 +133,8 @@
zend_bool modules_activated;

zend_bool file_uploads;
+   zend_bool upload_metter;
+   char * upload_metter_dir;

zend_bool during_request_startup;

diff -rubB orig/php-4.3.2/main/rfc1867.c php-4.3.2/main/rfc1867.c
--- orig/php-4.3.2/main/rfc1867.c   Sat May 24 00:37:16 2003
+++ php-4.3.2/main/rfc1867.cSun Jun 15 01:46:19 2003
@@ -676,6 +676,84 @@
return out;
 }

+typedef struct _Xdata {
+   int time_start;
+   int time_last;
+   int speed_average;
+   int speed_last;
+   int bytes_uploaded;
+   int bytes_total;
+   int files_uploaded;
+   char progress[1024];
+} Xdata;
+
+static void update_progress_metter_file(Xdata *X)
+{
+   int eta,s;
+   FILE *F;
+   TSRMLS_FETCH();
+
+   F = VCWD_FOPEN(X->progress, "wb");
+
+   s   = X->speed_average; if (s < 1) s=1;
+   eta = (X->bytes_total - X->bytes_uploaded) / s;
+
+   if (F) {
+   fprintf(F, 
"time_start=%d\ntime_last=%d\nspeed_average=%d\nspeed_last=%d\nbytes_uploaded=%d\nbytes_total=%d\nfiles_uploaded=%d\neta=%d\n",
+  X->time_start, X->time_last, X->speed_average, X->speed_last, 
X->bytes_uploaded, X->bytes_total, X->files_uploaded, eta
+ );
+   fclose(F);
+   }
+
+//   sapi_module.sapi_error(E_NOTICE, "metter: read %d of %d", SG(read_post_bytes), 
SG(request_info).content_length );
+}
+
+static void update_progress_metter(Xdata *X, int read, int total)
+{
+   int d,dt,dtx;
+   int bu;
+   int sp;
+
+
+   if (!X->time_start) {
+  X->time_start = X->time_last = time(NULL);
+
+  X->bytes_total= total;
+  X->bytes_uploaded = read;
+
+  X->speed_average  = X->speed_last = X->bytes_uploaded;
+
+  update_progress_metter_file(X);
+  return;
+   }
+
+   dt = time

[PHP-DEV] [PATCH] upload progress metter

2003-06-06 Thread Doru Petrescu

Hi,

 To make a long story short, I needed an upload progress metter, so the
users will something while their huge files are uploaded to the server. I
searched the net but only found for ASP, so I wrote one.
 Unfortunatly PHP needs a little patch to be willing to do this ...

 Here is how it works:
1. apply patch to php and recompile php (and apache if needed)
2. add something like this to http.conf

 #for php-upload-progress-bar
 
 php_value upload_metter 1
 php_value upload_metter_dir "/tmp/uploadbar"
 

  - This will activate the progress metter for /upload
  - And will tell it to write progress informations to /tmp/uploadbar

3. mkdir /tmp/uploadbar; chmod 777 /tmp/uploadbar
   I have to say that 0777 and /tmp are not the best choises from a
   security point of view. you should find a better place!

4. copy the demo scripts to /upload directory
5. point your browser to the index.php script. upload some files. enjoy!


 Here is how it really works:
1. index.php will generate and uniq ID for each upload. This ID will be
used to track the progress and report it.
2. a special field named 'UPLOAD_METTER_ID' is used to store this ID. make
sure this field is BEFORE any 'file' fields. put it at the begining of the
form!
3. onSubmit()-ing the form a small window will open where the progress.php
will display the actual progress bar.
4. php will check the value of 'upload_metter' and 'upload_metter_dir'
configuration options and the presence and value of 'UPLOAD_METTER_ID'
field
5. the progress file is stored in the directory named by 'upload_metter_dir'
   and the vlaue of UPLOAD_METTER_ID field is used as the name of the file
6. progress information is updated once a second by the php engine
7. script progress.php will use the ID field which it receives as a
parameter to locate the associated progress-file and read progress
information from it. then generate the little proggress bar
8. the progress bar will 'refresh' about once a second, depending on how
fast the network is going
9. when upload is completed, the progress.php script will remove the
progress file, and close the pop-up window.


NOTE: there is a good chance that this progress files will not be deleted
from various reasons (client don't have JS activated, or it closes the
popup while data is still uploaded, etc...), so there is a need to
periodically cleanup the directory of old files.


What the PATCH does:
- adding 2 new cinfiguration options to PHP: upload_metter and upload_metter_dir
- in rfc1867.c: changes rfc1867_post_handler() to make some calls to a
newly defined function that will update the progress metter:
update_progress_metter()
- in turn it calls update_progress_metter_file(), trying its best not to
update the file more than once a second.

I have tested it with php-4.2.3 and 4.3.2. atch for php-4.3.2 is attached.
a patch for 4.2.3 is also available. basically is the same thing.

the rest of the files and a live demo can be found here: http://pdoru.from.ro/


Please let me know if you have any problems/suggestions :-)


Best regards,
Doru Petrescu
Senior Software Engineer
Astral Telecom Bucuresti




---
diff -rubB orig/php-4.3.2/main/main.c php-4.3.2/main/main.c
--- orig/php-4.3.2/main/main.c  Thu May 22 01:54:38 2003
+++ php-4.3.2/main/main.c   Thu Jun  5 22:58:46 2003
@@ -345,7 +345,9 @@
STD_PHP_INI_BOOLEAN("file_uploads", "1",
PHP_INI_SYSTEM, OnUpdateBool,   file_uploads,  
 php_core_globals,   core_globals)
STD_PHP_INI_ENTRY("upload_max_filesize","2M",   
PHP_INI_SYSTEM|PHP_INI_PERDIR,  OnUpdateInt,
upload_max_filesize,php_core_globals,   core_globals)
STD_PHP_INI_ENTRY("post_max_size",  "8M",   
PHP_INI_SYSTEM|PHP_INI_PERDIR,  OnUpdateInt,post_max_size, 
 sapi_globals_struct,sapi_globals)
-   STD_PHP_INI_ENTRY("upload_tmp_dir", NULL,   
PHP_INI_SYSTEM, OnUpdateStringUnempty,  upload_tmp_dir, 
php_core_globals,   core_globals)
+   STD_PHP_INI_ENTRY("upload_tmp_dir", NULL,   
PHP_INI_ALL,OnUpdateStringUnempty,  upload_tmp_dir,
 php_core_globals,   core_globals)
+   STD_PHP_INI_ENTRY("upload_metter",  "0",
PHP_INI_ALL,OnUpdateBool,   upload_metter, 
 php_core_globals,   core_globals)
+   STD_PHP_INI_ENTRY("upload_metter_dir",  NULL,   
PHP_INI_ALL,OnUpdateStringUnempty,