FW: php-4.0RC1 HTTP PUT method
| From: | Gauthier, Ludovic | Date: | Thu, 20 Apr 2000 07:28:27 +0000 |
| Subject: | FW: php-4.0RC1 HTTP PUT method | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-18053@lists.php.net to get a copy of this message | ||
> Hello,
>
> I use Apache version 1.3.12 and php-4.0RC1 as a dynamic Apache module
> on Linux, and Solaris.
>
> For my project, I need to have the http PUT method support in Php.
> So I add the directive
> Script PUT /put.php
> to the httpd.conf Apache configuration file.
>
> When I publish an html document, everything goes right :
> the /put.php file is executed.
>
> But when I publish a php document, for example /index.php ,
> this is not the /put.php file that is executed, but the file that
> need to be published : /index.php
>
> This is not a problematic behavior for my application,
> I can do with it, but it just seems strange to me and I wonder
> if it's a normal behavior that will continue in future version of
> Php or if it is due to Apache configuration.
>
>
> I have tried to add the code that save the published document in the
> temporary file $PHP_UPLOADED_FILE_NAME.
> It is based on the patch from Manuel Lemos, and on the code of Php4
> for POST file upload.
> That's the first time I look at the Php code so there might be some
> incoherence but it works for me.
> I would appreciate some feedback.
>
> Ludovic Gauthier
> ludovic.gauthier@ensimag.imag.fr
>
>
> diff php-4.0RC1/main.c php-4.0RC1_with_PUT/main.c
> 971a972,975
> > if (!_gpc_flags[0] && !SG(headers_sent) &&
> > SG(request_info).request_method && !strcasecmp(SG(request_info).request_method,
> > "PUT")) {
> > php_treat_data(PARSE_PUT, NULL ELS_CC PLS_CC SLS_CC); /* PUT Data */
> > _gpc_flags[0]=1;
> > }
>
> diff php-4.0RC1/php_variables.h php-4.0RC1_with_PUT/php_variables.h
> 41a42
> > #define PARSE_PUT 4
>
> diff php-4.0RC1/php_variables.c php-4.0RC1_with_PUT/php_variables.c
> 250a251,255
> > if (arg==PARSE_PUT) {
> > sapi_handle_put(SLS_C);
> > return;
> > }
> >
>
> diff php-4.0RC1/SAPI.h php-4.0RC1_with_PUT/SAPI.h
> 134a135
> > SAPI_API void sapi_handle_put(SLS_D);
>
> diff php-4.0RC1/SAPI.c php-4.0RC1_with_PUT/SAPI.c
> 31a32,34
> > #include "ext/standard/file.h" /* for php_file_le_uploads() */
> > #include "php_variables.h"
> >
> 111a115,176
> >
> >
> > SAPI_API void sapi_handle_put(SLS_D) {
> > char *fn; // temporary uploded file name
> > FILE *fp; // temporary file pointer
> > long length; // file length
> >
> > int to_read_bytes, read_bytes = 0;
> > int write_bytes = 0;
> > char* buf=0;
> >
> > //php_log_err("sapi_handle_put");
> >
> > ELS_FETCH(); // i don't know what it do, and if it is needed. It was used in
> > PLS_FETCH(); // rfc1867.c when handling file upload
> >
> > length = SG(request_info).content_length;
> > fn = tempnam(PG(upload_tmp_dir), "php");
> >
> > if (length > PG(upload_max_filesize)) {
> > php_error(E_WARNING, "Max file size of %ld bytes exceeded - PUT file
> > not saved",
> > PG(upload_max_filesize));
> > SG(sapi_headers).http_response_code = 413; // Request Entity Too Large
> > fn = "none";
> > } else {
> > fp = fopen(fn,"wb");
> > if (!fp) {
> > php_error(E_WARNING, "File PUT Error - Unable to open
> > temporary file [%s]",
> > fn);
> > SG(sapi_headers).http_response_code = 500; // Internal Server
> > Error
> > return;
> > }
> >
> > buf = emalloc(length > SAPI_POST_BLOCK_SIZE ? SAPI_POST_BLOCK_SIZE :
> > length);
> > to_read_bytes = length;
> > while (to_read_bytes > 0) {
> > read_bytes = sapi_module.read_post(buf,
> > (to_read_bytes > SAPI_POST_BLOCK_SIZE ?
> > SAPI_POST_BLOCK_SIZE : to_read_bytes) SLS_CC
> > );
> > if (read_bytes<=0) > {
> > break;
> > }
> > to_read_bytes -= read_bytes;
> > write_bytes += fwrite(buf,1,read_bytes,fp);
> >
> > }
> > if (buf) {
> > efree(buf);
> > }
> > fclose(fp);
> > zend_list_insert(fn,php_file_le_uploads());
> > /* Tell PHP about the file so the destructor can unlink it later
> > */
> > if (write_bytes != length) {
> > php_error(E_WARNING, "Only %d bytes were written, expected to
> > write %ld",
> > write_bytes, length);
> > SG(sapi_headers).http_response_code = 500; // Internal Server
> > Error
> > }
> > }
> > php_register_variable("PHP_UPLOADED_FILE_NAME",fn,NULL ELS_CC PLS_CC);
> > }
> >