Index: php4/main/SAPI.c =================================================================== RCS file: /repository/php4/main/SAPI.c,v retrieving revision 1.75 diff -u -r1.75 SAPI.c --- php4/main/SAPI.c 2000/05/18 15:34:21 1.75 +++ php4/main/SAPI.c 2000/06/13 10:50:25 @@ -28,6 +28,8 @@ #endif #include "rfc1867.h" +#include "ext/standard/file.h" /* for php_file_le_uploads() */ +#include "php_variables.h" #ifdef PHP_WIN32 #define STRCASECMP stricmp @@ -103,6 +105,66 @@ SAPI_API void sapi_free_header(sapi_header_struct *sapi_header) { efree(sapi_header->header); +} + + +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("php: 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_log_err("php: PUT > 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_log_err("php: can't open temp file"); + 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_log_err("php: hasn't write all the bytes"); + 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_PUT_FILENAME",fn,NULL ELS_CC PLS_CC); + //php_log_err("php: /sapi_handle_put"); } Index: php4/main/SAPI.h =================================================================== RCS file: /repository/php4/main/SAPI.h,v retrieving revision 1.47 diff -u -r1.47 SAPI.h --- php4/main/SAPI.h 2000/05/18 15:34:21 1.47 +++ php4/main/SAPI.h 2000/06/13 10:50:25 @@ -132,6 +132,7 @@ SAPI_API int sapi_send_headers(void); SAPI_API void sapi_free_header(sapi_header_struct *sapi_header); SAPI_API void sapi_handle_post(void *arg SLS_DC); +SAPI_API void sapi_handle_put(SLS_D); SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry); SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry); Index: php4/main/main.c =================================================================== RCS file: /repository/php4/main/main.c,v retrieving revision 1.268 diff -u -r1.268 main.c --- php4/main/main.c 2000/06/12 20:22:17 1.268 +++ php4/main/main.c 2000/06/13 10:50:25 @@ -1012,6 +1012,10 @@ php_treat_data(PARSE_POST, NULL ELS_CC PLS_CC SLS_CC); /* POST Data */ _gpc_flags[0]=1; } + 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; + } break; case 'c': case 'C': Index: php4/main/php_variables.c =================================================================== RCS file: /repository/php4/main/php_variables.c,v retrieving revision 1.14 diff -u -r1.14 php_variables.c --- php4/main/php_variables.c 2000/05/18 15:34:21 1.14 +++ php4/main/php_variables.c 2000/06/13 10:50:25 @@ -248,6 +248,11 @@ return; } + if (arg==PARSE_PUT) { + sapi_handle_put(SLS_C); + return; + } + if (arg == PARSE_GET) { /* GET data */ var = SG(request_info).query_string; if (var && *var) { Index: php4/main/php_variables.h =================================================================== RCS file: /repository/php4/main/php_variables.h,v retrieving revision 1.4 diff -u -r1.4 php_variables.h --- php4/main/php_variables.h 2000/02/19 20:12:26 1.4 +++ php4/main/php_variables.h 2000/06/13 10:50:25 @@ -39,6 +39,8 @@ #define PARSE_GET 1 #define PARSE_COOKIE 2 #define PARSE_STRING 3 +#define PARSE_PUT 4 + void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC); void php_import_environment_variables(ELS_D PLS_DC);