2011-01-20 22 views
1

我試圖打破一個文件夾路徑如何擊穿PHP

例如文件夾路徑:home/player/jay/profile/pictures

home 
home/players 
home/players/jay 
home/players/jay/profile 
home/players/jay/profile/pictures 

我tryed利用這一點,但我不能得到它顯示正確的

$new_folders = explode("/","home/player/jay/profile/pictures"); 

for ($i = 0; $i < sizeof($new_folders); $i++) { 
    for ($r = 0; $r < $i + 1; $r++) { 
     $create_new_path .= $new_folders[$r]; 
     if ($r != $i) { 
      $create_new_path .= "/"; 
     } 
    } 

    //ftp_mkdir($conn_id, "httpdocs/user_images/".$create_new_path); 
    //ftp_chmod($conn_id, 0777, "httpdocs/user_images/".$create_new_path); 
} 

回答

5
$breakdown = array(); 
$dirs = explode('/', 'home/player/jay/profile/pictures'); 
$path = ''; 
foreach($dirs as $dir) { 
    $path .= ($path !== '' ? '/' : '') . $dir; 
    $breakdown[] = $path; 
} 
// result is in $breakdown