【发布时间】:2014-04-08 05:19:07
【问题描述】:
我有以下 PHP 结构:
if ((move_uploaded_file($_FILES['file1']['tmp_name'],$newname))) {
echo "It's done! The file has been saved as: ".$newname;
//Writes the information to the database
$y = mysqli_query($con,"SELECT id FROM files ORDER BY id DESC LIMIT 1") ;
$a = mysqli_fetch_array($y,MYSQL_ASSOC);
$index = (int)$a['id']+1;
$x = mysqli_query($con,"INSERT INTO files (id,title,link) VALUES ('$index', '$title', '$file')") ;
header('Location: upload2.php');
exit();
而且这个结构有个问题是它不重定向……我猜是header函数不像我用的那样工作。
我的代码的最后两行需要一个替代解决方案,所以如果文件上传成功,我想在数据库中写入信息,然后重定向到页面。
我怎样才能实现这个功能?
【问题讨论】:
-
你试过放完整的基本路径吗?
-
您只能在到目前为止还没有发送任何标头的情况下进行重定向。您已经发送了标头...
echo "It's done! The file has been saved as: ".$newname; -
在调用
header()函数之前,您正在执行echo。如果您登录时出错,您的日志很可能会显示类似Warning: Cannot modify header information - headers already sent的错误。删除echo并尝试使用文件的完整路径。 -
回显信息后不能使用header功能。
-
去掉
exit();看看有没有效果
标签: php forms redirect file-upload upload