public function testRecursiveMkdir_パーミッションを指定しない場合_0777でディレクトリが作られる() { $path = realpath(dirname(__FILE__)) . "/../../../tmp/dir1/dir2/dir3/"; $result = SC_Utils::recursiveMkdir($path); $this->expected = '0777'; $this->actual = substr(sprintf('%o', fileperms($path)), -4); $this->verify('作成したディレクトリのパーミッション'); }
public function testRecursiveMkdir_パーミッションを指定しない場合_0777でディレクトリが作られる() { $path = realpath(dirname(__FILE__)) . "/../../../tmp/dir1/dir2/dir3/"; $result = SC_Utils::recursiveMkdir($path); if (DIRECTORY_SEPARATOR == '\\') { // Windows環境ではパーミッションを指定したディレクトリ作成が出来ない $this->expected = true; $this->actual = file_exists($path); $this->verify('作成したディレクトリがあるかどうか'); } else { $this->expected = '0777'; $this->actual = substr(sprintf('%o', fileperms($path)), -4); $this->verify('作成したディレクトリのパーミッション'); } }
/** * ディレクトリを再帰的に作成する. * * mkdir 関数の $recursive パラメーターを PHP4 でサポートする. * * @param string $pathname ディレクトリのパス * @param integer $mode 作成するディレクトリのパーミッション * @return boolean 作成に成功した場合 true; 失敗した場合 false * @see http://jp.php.net/mkdir */ function recursiveMkdir($pathname, $mode = 0777) { /* * SC_Utils_Ex への再帰は無限ループやメモリリークの懸念 * 自クラスへ再帰する. */ is_dir(dirname($pathname)) || SC_Utils::recursiveMkdir(dirname($pathname), $mode); return is_dir($pathname) || @mkdir($pathname, $mode); }
function testRecursiveMkdir() { $tmp_dir = sys_get_temp_dir(); $dir = '/foo/bar'; $results = false; if (is_dir($tmp_dir . $dir)) { rmdir($tmp_dir . '/foo/bar'); rmdir($tmp_dir . '/foo'); } $results = SC_Utils::recursiveMkdir($tmp_dir . $dir, 0777); $this->assertTrue($results); }