}
}elseif (preg_match("~^CWD ([A-Za-z./]+)\r\n$~", $buf, $m)) {
- change_dir($m[1]);
- fputs($s, "250 CWD command successful.\r\n");
+ if (isset($bug77680)) {
+ fputs($s, "550 Directory change to $m[1] failed: file does not exist\r\n");
+ var_dump($buf);
+ } else {
+ change_dir($m[1]);
+ fputs($s, "250 CWD command successful.\r\n");
+ }
} elseif (preg_match("~^NLST(?: ([A-Za-z./]+))?\r\n$~", $buf, $m)) {
if (isset($bug7216)) {
fputs($s, "257 OK.\r\n");
} else {
+ if (isset($bug77680)) {
+ var_dump($buf);
+ }
fputs($s, "257 \"/path/to/ftproot$cwd$m[1]\" created.\r\n");
}
/* find a top level directory we need to create */
while ((p = strrchr(buf, '/'))) {
- *p = '\0';
- php_stream_printf(stream, "CWD %s\r\n", buf);
+ *p = '\0';
+ php_stream_printf(stream, "CWD %s\r\n", strlen(buf) ? buf : "/");
result = GET_FTP_RESULT(stream);
if (result >= 200 && result <= 299) {
*p = '/';
break;
}
- }
- if (p == buf) {
- php_stream_printf(stream, "MKD %s\r\n", resource->path);
- result = GET_FTP_RESULT(stream);
- } else {
- php_stream_printf(stream, "MKD %s\r\n", buf);
- result = GET_FTP_RESULT(stream);
- if (result >= 200 && result <= 299) {
- if (!p) {
- p = buf;
- }
- /* create any needed directories if the creation of the 1st directory worked */
- while (++p != e) {
- if (*p == '\0' && *(p + 1) != '\0') {
- *p = '/';
- php_stream_printf(stream, "MKD %s\r\n", buf);
- result = GET_FTP_RESULT(stream);
- if (result < 200 || result > 299) {
- if (options & REPORT_ERRORS) {
- php_error_docref(NULL, E_WARNING, "%s", tmp_line);
- }
- break;
+ }
+
+ php_stream_printf(stream, "MKD %s\r\n", strlen(buf) ? buf : "/");
+ result = GET_FTP_RESULT(stream);
+
+ if (result >= 200 && result <= 299) {
+ if (!p) {
+ p = buf;
+ }
+ /* create any needed directories if the creation of the 1st directory worked */
+ while (p != e) {
+ if (*p == '\0' && *(p + 1) != '\0') {
+ *p = '/';
+ php_stream_printf(stream, "MKD %s\r\n", buf);
+ result = GET_FTP_RESULT(stream);
+ if (result < 200 || result > 299) {
+ if (options & REPORT_ERRORS) {
+ php_error_docref(NULL, E_WARNING, "%s", tmp_line);
}
+ break;
}
}
+ ++p;
}
}
- efree(buf);
+
+ efree(buf);
}
php_url_free(resource);
--- /dev/null
+--TEST--
+Recursive mkdir() on ftp should create missing directories.
+--SKIPIF--
+<?php
+if (array_search('ftp',stream_get_wrappers()) === FALSE) die("skip ftp wrapper not available.");
+if (!function_exists('pcntl_fork')) die("skip pcntl_fork() not available.");
+?>
+--FILE--
+<?php
+$bug77680=1;
+
+require __DIR__ . "/../../../ftp/tests/server.inc";
+
+$path = "ftp://localhost:" . $port."/one/two/three/";
+mkdir($path, 0755, true);
+
+?>
+==DONE==
+--EXPECTF--
+string(20) "CWD /one/two/three
+"
+string(14) "CWD /one/two
+"
+string(10) "CWD /one
+"
+string(7) "CWD /
+"
+string(7) "MKD /
+"
+string(10) "MKD /one
+"
+string(14) "MKD /one/two
+"
+string(20) "MKD /one/two/three
+"
+==DONE==