如何通過php循環在目錄內製作目錄?
實施例:http://site_name/a/b/c/d
首先創建一個則b內的則c內然後B ....
問題是在這裏,A,B,C,D在根目錄中創建就不一一內的所有文件夾。 這裏是我的代碼 -如何通過php循環在目錄內製作目錄?
<?php
$url = "http://site_name/a/b/c/d";
$details1 = parse_url(dirname($url));
$base_url = $details1['scheme'] . "//" . $details1['host'] . "/";
if ($details1['host'] == 'localhost') {
$path_init = 2;
}else {
$path_init = 1;
}
$paths = explode("/", $details1['path']);
for ($i = $path_init; $i < count($paths); $i++) {
$new_dir = '';
$base_url = $base_url . $paths[$i] . "/";
$new_dir = $base_url;
if (FALSE === ($new_dir = folder_exist($paths[$i]))) {
umask(0777);
mkdir($new_dir . $paths[$i], 0777, TRUE);
}
}
function folder_exist($folder)
{
// Get canonicalized absolute pathname
$path = realpath($folder);
// If it exist, check if it's a directory
return ($path !== false AND is_dir($path)) ? $path : false;
}
?>
你嘗試過這麼遠嗎?添加您的代碼 – tausun
請再次檢查,我已經添加了代碼,您可以瞭解問題。 –
它有什麼問題?請不要讓我們猜測,提供明確的信息,你嘗試了什麼,你的問題是什麼。 – Burki