cvs: php4 /ext/standard ftp_fopen_wrapper.c

From: Date: Tue, 22 Apr 2003 04:13:09 +0000
Subject: cvs: php4 /ext/standard ftp_fopen_wrapper.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-20426@lists.php.net to get a copy of this message
pollita Tue Apr 22 00:13:09 2003 EDT Modified files: /php4/ext/standard ftp_fopen_wrapper.c Log: Feature Request #7121. Allow overwritting of files via ftp:// wrapper. Requires context option: $context['ftp']['overwrite'] != 0 Index: php4/ext/standard/ftp_fopen_wrapper.c diff -u php4/ext/standard/ftp_fopen_wrapper.c:1.47 php4/ext/standard/ftp_fopen_wrapper.c:1.48 --- php4/ext/standard/ftp_fopen_wrapper.c:1.47 Thu Feb 27 13:16:34 2003 +++ php4/ext/standard/ftp_fopen_wrapper.c Tue Apr 22 00:13:09 2003 @@ -17,7 +17,7 @@ | Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: ftp_fopen_wrapper.c,v 1.47 2003/02/27 18:16:34 wez Exp $ */ +/* $Id: ftp_fopen_wrapper.c,v 1.48 2003/04/22 04:13:09 pollita Exp $ */ #include "php.h" #include "php_globals.h" @@ -146,6 +146,8 @@ php_stream *reuseid=NULL; char *tpath, *ttpath, *hoststart=NULL; size_t file_size = 0; + zval **tmpzval; + int allow_overwrite = 0; tmp_line[0] = '\0'; @@ -312,10 +314,25 @@ php_stream_notify_file_size(context, file_size, tmp_line, result); } } else { - /* when writing file, it must NOT exist */ + /* when writing file, it must NOT exist, unless a context option exists which allows it */ + if (context && php_stream_context_get_option(context, "ftp", "overwrite", &tmpzval) == SUCCESS) { + allow_overwrite = Z_LVAL_PP(tmpzval); + } if (result <= 299 && result >= 200) { - errno = EEXIST; - goto errexit; + if (allow_overwrite) { + /* Context permits overwritting file, + so we just delete whatever's there in preparation */ + php_stream_write_string(stream, "DELE "); + php_stream_write_string(stream, resource->path); + php_stream_write_string(stream, "\r\n"); + result = GET_FTP_RESULT(stream); + if (result >= 300 || result <= 199) { + goto errexit; + } + } else { + errno = EEXIST; + goto errexit; + } } }

« previous php.cvs (#20426) next »