使用DropzoneJS上传PHP重定向用户一次文件

时间:2013-10-21 14:34:58

标签: php redirect upload dropzone.js

问题:

PHP代码不会使用header()将用户重定向到目标页面。

代码(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');   
        }
    }
?>

所需功能

获取header()以将用户重定向到explorer.php。是的,文件成功上传没有任何问题。但是用户继续留在同一页面(upload.php)。

1 个答案:

答案 0 :(得分: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');   
 }