PHP ディレクトリを再帰的に作成する

PHP ディレクトリを再帰的に作成する


/**
 * ディレクトリ生成
 **/
function makeDirectory($path)
{
	$result = false;
	
	// ディレクトリを確認
	if(file_exists($path))
	{
		$result = true;
	}
	
	if($result === false)
	{
		// ディレクトリが存在しない場合はディレクトリを作成
		mkdir($path, 0755, true);
		chmod($path, 0755);
		$result = true;
	}
	
	return $result;
}

makeDirectory('/path/to/my/dir');
ディレクトリが『path』までしか存在しない場合、再帰処理で
残りの『/to/my/dir』までを作成する

Comments are closed.