summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2003-04-22 04:13:09 +0000
committerSara Golemon <pollita@php.net>2003-04-22 04:13:09 +0000
commitcb89565ba4deab745e38b9d9f93f3e504d3b2f55 (patch)
tree54c0b87c88ebf4c4ae32dfd698bd5c834dce9150
parentc523fc47666d66786c9c50231465892412608fd5 (diff)
downloadphp-git-cb89565ba4deab745e38b9d9f93f3e504d3b2f55.tar.gz
Feature Request #7121.
Allow overwritting of files via ftp:// wrapper. Requires context option: $context['ftp']['overwrite'] != 0
-rw-r--r--ext/standard/ftp_fopen_wrapper.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c
index e088413187..3ec09c1fa7 100644
--- a/ext/standard/ftp_fopen_wrapper.c
+++ b/ext/standard/ftp_fopen_wrapper.c
@@ -146,6 +146,8 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, ch
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 * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, ch
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;
+ }
}
}