问题:
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)。
答案 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');
}