无法修改标头信息 - 已由错误发送的标头

nec*_*tar -4 php mysql

我的代码 -

if ($result) 
{
    $row = $result->fetch_object();
    $filename = $row->src;

    $q = "delete from photos WHERE id=$fileid";
    $result = $mysqli->query($q) or die(mysqli_error($mysqli));
    if ($result) 
    {
        $filepath = "./images/";
        if(fileDelete($filepath,$filename))
        {
            echo "success";
            header("Location: index.php");
            exit;
        }
        else echo "failed";
    }
}
Run Code Online (Sandbox Code Playgroud)

输出 -

success
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\pics\deletepic.php:31) in C:\xampp\htdocs\pics\deletepic.php on line 32

Mch*_*chl 5

在发送标头之前无法回显ANYTHING.