2013-10-21 29 views
0

問題:PHP重定向用戶一旦文件被上傳與DropzoneJS

PHP代碼不重定向用戶使用報頭到目標頁面()。

碼(upload.php的):

<?php 
    session_start(); 

    $folder  = 'upload'; 

    if (!empty($_FILES)) 
    { 
     // Set temporary name 
     $tmp = $_FILES['file']['tmp_name']; 

     // Set target path and file name 
     $target = $folder . '/' . $_FILES['file']['name']; 

     // Upload file to target folder 
     $status = move_uploaded_file($tmp, $target); 

     if ($status) 
     { 
      // Set session with txtfile name 
      $_SESSION['txtfile'] = $_FILES['file']['name']; 

      // Redirect user 
      header('Location: explorer.php'); 
     } 
    } 
?> 

所需的功能:

獲取頭()合作,以重定向用戶explorer.php。是的,文件成功上傳沒有任何問題。但用戶繼續留在同一頁面(upload.php)。

+0

爲$狀態真的嗎?如果是這樣你需要退出(); –

+0

@SajunaFernando我在頭後添加了一個exit(),沒有任何成功。 – kexxcream

+0

試試這個: 嘗試{ $ status = move_uploaded_file($ tmp,$ target); (Exception $ oException){ var_dump($ oException);死; } –

回答

0

試試這個:

$status = false; 
if (is_uploaded_file($tmp) == true) { 
    $status = @move_uploaded_file($tmp, $target); 
} 
else { 
    $status = @copy($tmp, $target); 
} 

if(file_exists($target)){ 
    $status = true; 
} 

if ($status) 
{ 
    // Set session with txtfile name 
    $_SESSION['txtfile'] = $_FILES['file']['name']; 

    // Redirect user 
    header('Location: explorer.php'); 
} 
+0

剛試過這個解決方案,上傳後沒有任何反應。該文件被上傳,並在error_log中沒有錯誤。 – kexxcream

+0

你可以將它添加到腳本的頂部,只需確保並再試一次:ini_set('display_errors','On'); error_reporting(E_ALL); –

+0

添加了兩個錯誤處理程序。上傳文件時沒有錯誤。只是考慮傾銷DropzoneJS並與其他一些jQuery上傳文件一起使用。對於這樣的問題感到麻煩太多。 – kexxcream