标头不是';t工作,很确定之前没有输出';s已调用


header isn't working, pretty sure there is no output before it's called

这是我的图像上传代码,标题不起作用,它停留在这个页面上。

<?php 
if ($_FILES ["file"]["type"] == "image/jpeg") {
    if ($_FILES ["file"]["error"] > 0) {
        header ("index.php?s=2");
    } else {
        if ($dir = opendir ('Images')) {
            readdir ($dir);
            readdir ($dir);
            $count = 0;
            while (false !== ($image = readdir ($dir))) {
                $count++;
            }
            move_uploaded_file ($_FILES ["file"]["tmp_name"], "Images/" . ($count + 1) . ".jpg");
            header ("index.php?s=0");
        }
    }
} else {
    header ("index.php?s=1");
}
?>

我读

请记住,在发送任何实际输出之前,必须调用header(),无论是通过普通的HTML标记、文件中的空行还是从PHP发送。使用include()或require()、函数或其他文件访问函数读取代码,并在调用header()之前输出空格或空行,这是一个非常常见的错误。使用单个PHP/HTML文件时也存在同样的问题。

来自PHP手册,但我认为我没有任何输出。

重定向的正确方法,

header("Location:index.php?s=0");

这不是一个有效的标头。也许您打算使用Location标头进行响应。