2
I want to insert a news along with the image file in a single post, the problem is that I would like to create a folder with the news ID where the image will be stored. It’s happening that the Insert is working but the upload no, some light or easier way to do this?
$imagem = $_FILES['imagem'];
$sqlInsert = "INSERT INTO noticias (titulo,categoria,conteudo) VALUES (:titulo,:categoria,:conteudo)";
$stmt = DB::prepare($sqlInsert);
$stmt->bindParam("titulo", $titulo);
$stmt->bindParam("categoria", $categoria);
$stmt->bindParam("conteudo", $conteudo);
$stmt->execute();
$ultimoid = DB::lastInsertId();
$dir = "../imagens/$ultimoid";
$pasta = mkdir("$dir", 0775);
if(is_dir("$dir")){
if($arquivo != "none") {
if (copy($_FILES['imagem']['tmp_name'], $dir . $_FILES['imagem']['name'])) {
$arquivo1 = $_FILES['imagem']['name'];
$sqlInsert = "UPDATE noticias SET imagem=:imagem WHERE idnoticia=$ultimoid";
}
}
remembering that I made a summary of the code only with the parts that I believe is where is giving problem, any doubt put the whole code
On the line that has copy, do not need to use something like "joinPaths" ? the path is right ?
– Isvaldo Fernandes
in theory whether the directory was created the path is right
– Arsom Nolasco