标头功能不会与/ variables重定向

时间:2014-04-02 07:32:05

标签: php http uploading

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL|E_STRICT);
include_once("alphaID.php");
include_once("displayimage.php");
//include_once("insertdata.php");
//generate unique id
$key = microtime() + floor(rand()*10000);
$newname = alphaID($key);
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
$ext = explode('.',$_FILES['userfile']['name']);
$extension = '.'.$ext[1];
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$filepath = '/var/www/html/testing/'.$newname.$extension;
move_uploaded_file($_FILES['userfile']['tmp_name'], $filepath));
header('Location: displayimage.php?img='.$newname.);
exit;
?>

我似乎无法让底部的标题功能起作用。我无法在代码中看到任何输出,并试图尝试使其工作。

2 个答案:

答案 0 :(得分:1)

发送标头之前,您无法输出任何内容。由于您在displayimage.php中输出,您的位置功能将失败。

以下是关于此问题的StackOverflow的一些很好的阅读:

How to fix "Headers already sent" error in PHP

<强> 修改

标头调用中存在语法错误。你有一个额外的时期。删除$ newname后的句点。你应该:

header('Location: displayimage.php?img='.$newname);

另外,你有太多了(在你的move_uploaded_file函数上。这也导致语法错误。你应该有:

move_uploaded_file($_FILES['userfile']['tmp_name'], $filepath);

如果您没有看到任何输出,通常会出现语法错误。只有一个语法错误将阻止整个页面执行。

答案 1 :(得分:-1)

header('Location: displayimage.php?img='.$newname**.**); 

pb是附加点

相关问题