1
Good to have a problem here that I have tried to solve in several ways without success. It follows part that is catching
$stmt->execute(); -------> final do insert até aki ok
if (DB::lastInsertId()) {
// pego o ultimo id
$lastId = DB::lastInsertId();
// crio o diretorio
mkdir ("../img/$lastId", 0755 ); ---> ate aqui ok o diretorio e criado usando o ultimo id
---------------------> a partir daqui que esta o problema
// upload e update
// altero o nome
$filename = time() . '_' . $_FILES["imagem"]["name"];
$diretorio = '../img/$lastId/';
$filepath = '$diretorio' . $filename;
move_uploaded_file($_FILES["imagem"]["tmp_name"], $filepath)
// insere no bd
$sqlInsert2 = "UPDATE noticias SET imagem=$filename WHERE idnoticia=$lastId";
$stmt = DB::prepare($sqlInsert2);
$stmt->bindParam("imagem", $filename);
$stmt->execute();
setMessage("Notícia $lastId $filename cadastrado com sucesso.");
redirect("noticiasListar.php");
the other news items are being inserted, the folder is being created, just not uploading the image or updating the image in the comic
some solution?
If each news has a unique image, why not save the file named with the news id, or even inside the folder you created using the id, but with a default name?
– Luis Henrique