2013-10-21 30 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