2015-07-21 52 views
-1

我有一個按鈕,我的用戶可以刪除他們創建的某個目錄。他們去一個確認頁面,當他們選擇「是」,該代碼被激活:刪除目錄後PHP頭位置不重定向

$fileName=$_POST['filename']; 
$siteName=$_POST['sitename']; 
$user=$_POST['user']; 
$subdir=$_POST['subdir']; 
if ($subdir=="yes") { 
    $dirName=$_POST['dirname']; 
    $path="../s/{$siteName}/{$dirName}"; 

    if (is_dir($path) === true) 
    { 
     $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST); 

     foreach ($files as $file) 
     { 
      if (in_array($file->getBasename(), array('.', '..')) !== true) 
      { 
       if ($file->isDir() === true) 
       { 
        rmdir($file->getPathName()); 
       } 

       else if (($file->isFile() === true) || ($file->isLink() === true)) 
       { 
        unlink($file->getPathname()); 
       } 
      } 
     } 

     return rmdir($path); 
    header("location:edit.php?action=edit&user=$myusername"); 

    } 
    else if ((is_file($path) === true) || (is_link($path) === true)) 
    { 
     return unlink($path); 
    } 
    header("location:edit.php?action=edit&user=$myusername"); 

} 
header("location: edit.php?action=edit&user=$myusername"); 

我試圖把header("location: edit.php?action=edit&user=$myusername");在所有三個上述點,但它永遠不會重定向。當我手動進入該頁面時,該目錄被刪除。我的問題是爲什麼它不會自動重定向?

+0

加'exit();'在重定向嘗試後立即執行,因此它不會執行更多代碼並重定向ri ght然後...並且不要在分支中返回''後面的重定向 – developerwjk

+0

沒有工作...之後應該添加哪個重定向? – k97513

+0

後面那些人,如果分支 – developerwjk

回答

0

return rmdir(...) header(....)

你已經回來了,所以頭將永遠不會被髮送

正確的代碼:

rmdir(...); 
header(...); 
return; 

還就上線,這個是不必要的

+0

謝謝,這工作完美! – k97513

+0

不客氣:) –