PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Networking » Net_FTP » Bug #240

mkdir() with $recursive===true doesn't support "single" directories

Details

Submitted2003-11-13 19:30 UTC
Fromme at mkone dot net
Assignedtoby
StatusClosed
PackageNet_FTP
PHP Version4.3.3
OSSuse Linux
Roadmaps(Not assigned)

Comments

[2003-11-13 19:30 UTC] me at mkone dot net

Description:
------------
If mkdir() is set up with recursive directory creation and only a simple directory is given, this directory is not be created.

The problem seems to be here:

[Line 290 FTP.php]
while (false !== ($pos = strpos($dir, '/', $pos + 1))){
$elements[] = substr($dir, 0, $pos);
}

$elements is empty after that, instead of having one element.

Reproduce code:
---------------
$chk = $test->mkdir('path', true);
var_dump($chk);

Expected result:
----------------
bool(true)

and directory 'path' existing on host

Actual result:
--------------
bool(true)

directory 'path' does NOT exist

[2003-12-31 10:48 UTC] chip at php dot net

Patch should Fix this bug.

Also will now properly return an error if a subfolder in a recursive mkdir failed.
--- FTP.php.dist 2003-12-31 10:42:16.000000000 +0000
+++ FTP.php 2003-12-31 10:50:56.000000000 +0000
@@ -283,13 +283,17 @@
return true;
}
} else {
- $pos = 0;
+ if(strpos($dir, '/') === false)
+ return $this->mkdir($dir,false);
+ $pos = 0;
$elements = array();
while (false !== ($pos = strpos($dir, '/', $pos + 1))){
$elements[] = substr($dir, 0, $pos);
}
foreach ($elements as $element){
- $this->mkdir($element, false);
+ $res = $this->mkdir($element, false);
+ if($res !== true)
+ return $res;
}
return true;
}