0
Good people. This question should be the most asked but I’ve tried everything (I think I tried everything) but it still doesn’t 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);
}
?>
Okay, I’ve been looking at some of the common errors that trigger this error like Excerpts and prints, html tags, whitespace, etc and I’ve tried to fix it but it keeps giving the same error.
By the way, this is my mistake 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
The 105 line is where the tag starts <?php
and supposedly that’s where the outputs are supposed to be launched. I just can’t find the why of this happening!!
Someone can figure this out for me?!
PS - the code shown here is without changes that I did to try to solve.
Thank you
PHP error - Cannot Modify header information There are a few more answers here, an alternative you didn’t talk about was to check the archive’s Find.
– rray
What is line 155?
– Luis Henrique
if the script you posted starts counting on line 105 and has 48 lines, so, I’m missing more codes to get to line 155.
– Daniel Omine
If you are using Sublime or another text editor that has the Save With Encoding option ... UTF8, do so. In English, Save with Encoding... UTF8. Sometimes it saves with UT8 with GOOD.
– Diego Souza
when directed to the page that would have to run the head, open the debugging console of your browser, see the code that it presents, if there is line break, comment or some code in the html displayed, theoretically would have to have only the line 1 empty.
– Michel Simões