0

问题:

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

代码(上传.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)。

4

1 回答 1

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');   
 }
于 2013-10-21T14:51:51.673 回答