【发布时间】:2011-04-01 20:39:37
【问题描述】:
当我在 php 中使用标头(位置:...)重定向时会引发警告,为什么?
这是警告:
警告:无法修改标头信息 - 标头已由第 26 行 ~\addMarket1.php 中的(输出开始于 ~\index.php:51)发送
这是代码:
$folder = 'images/markets/';
$orig_w = 500;
if( isset($_POST['submit']) )
{
$imageFile = $_FILES['image']['tmp_name'];
$filename = basename( $_FILES['image']['name']);
if(strstr($_FILES["image"]["type"],"image")){
list($width, $height) = getimagesize($imageFile);
$src = imagecreatefromjpeg($imageFile);
$orig_h = ($height/$width)* $orig_w;
$tmp = imagecreatetruecolor($orig_w, $orig_h);
imagecopyresampled($tmp, $src, 0,0,0,0,$orig_w,$orig_h,$width,$height);
imagejpeg($tmp, $folder.$filename,100);
imagedestroy($tmp);
imagedestroy($src);
$filename = urlencode($filename);
mysql_query("insert into photos (`image`) values ('$filename')");
// echo '<meta http-equiv="refresh" content="0;URL=../Admin/?p=crop&filename=$filename&height=$orig_h">';
header("Location: ../Admin/crop.php?filename=$filename&height=$orig_h");
}
else
echo "The file uploaded is not image. Please choose jpg, png,gif or png image !";
}
【问题讨论】:
-
这意味着至少1字节的数据已经发送到浏览器。检查空格。
-
请注意,
Location标头必须以绝对 URI 作为值,而不是相对 URI,即使它与相对 URI 一起“工作”。 -
老实说,在搜索中输入单词有那么难吗? stackoverflow.com/search?q=headers+already+sent+php
-
Headers already sent的可能重复