Problem with sending headers [duplicate]

0

Good people. This question should be the most asked but I have tried everything (I think I tried everything) but it still does not give.

I have a php file here

<?php
                $ligacao = mysqli_connect("localhost", "root", "", "banco");
                if (mysqli_connect_errno()) {
                    echo "Erro na ligação MySQL: " . mysqli_connect_error();
                }
                if (isset($_POST["submit"])) {

                    $seccao = $_POST["seccao"];
                    $target_dir = "img/galeria/" . $seccao . "/";
                    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
                    $uploadOk = 1;
                    $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);

                    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
                    if ($check !== false) {
                        $uploadOk = 1;
                    } else {
                        echo "O ficheiro não é uma imagem.";
                        $uploadOk = 0;
                    }
                    if ($_FILES["fileToUpload"]["size"] > 500000) {
                        echo "Desculpa, o ficheiro é demasiado grande.";
                        $uploadOk = 0;
                    }
                    if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
                        echo "Apenas JPEG, JPG, PBG, GIF são permitidos";
                        $uploadOk = 0;
                    }
                    if ($uploadOk == 0) {
                        echo "O ficheiro não foi carregado.";
                    } else {
                        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
                            echo "O ficheiro " . basename($_FILES["fileToUpload"]["name"]) . " foi submetido. <a href='index.php'>Clique aqui</a> para voltar para o inicio";
                        } else {
                            echo "Houve um erro com o upload do ficheiro.";
                        }
                    }
// colocar em variáveis os valores recebidos do formulário (método post) e que foram colocados no array associativo $_POST.
                    $nome = $_POST["nome"];
                    $descricao = $_POST["descricao"];
                    $foto = basename($_FILES["fileToUpload"]["name"]);

                    $sql = "insert into foto (nome, imagem, descricao, seccao) values ('$nome', '$foto', '$descricao', '$seccao')";

                    $resultado = mysqli_query($ligacao, $sql);
                    mysqli_close($ligacao);
                }
                ?>
Well, I've been looking at some of the common mistakes that trigger this error like the echos and prints, the html tags, the blanks, etc. and I've tried to fix it but it always keeps giving the same error. Already the error that gives me is this Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\projeto\inserirFotos.php:105) in C:\xampp\htdocs\projeto\inserirFotos.php on line 155 Line 105 is where the <?php tag begins and is supposed to be where the outputs are supposed to be launched. Only I can not find why this happens !! Can someone figure this out for me?!

PS - The code shown here is without any changes I made to try to resolve it.

Thank you

    
asked by anonymous 03.06.2015 / 19:18

1 answer

-1

At first the header will only work if it is the first sentence, there can not be echo, text or anything else before it, the header must be the first PHP execution statement.

    
03.06.2015 / 19:52