Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. $stmt->execute(); -------> final do insert até aki ok
  2. if (DB::lastInsertId()) {
  3. // pego o ultimo id
  4. $lastId = DB::lastInsertId();
  5. // crio o diretorio
  6. mkdir ("../img/$lastId", 0755 ); ---> ate aqui ok o diretorio e criado usando o ultimo id
  7. ---------------------> a partir daqui que esta o problema
  8. // upload e update
  9. // altero o nome
  10. $filename = time() . '_' . $_FILES["imagem"]["name"];
  11. $diretorio = '../img/$lastId/';
  12. $filepath = '$diretorio' . $filename;
  13. move_uploaded_file($_FILES["imagem"]["tmp_name"], $filepath)
  14. // insere no bd
  15. $sqlInsert2 = "UPDATE noticias SET imagem=$filename WHERE idnoticia=$lastId";
  16. $stmt = DB::prepare($sqlInsert2);
  17. $stmt->bindParam("imagem", $filename);
  18. $stmt->execute();
  19.  
  20.  
  21. setMessage("Notícia $lastId $filename cadastrado com sucesso.");
  22. redirect("noticiasListar.php");
  23.  
  24. $diretorio = '../img/$lastId/';
  25. $filepath = '$diretorio' . $filename;
  26.  
  27. $diretorio = '../img/' . $lastId . '/';
  28. $filepath = $diretorio . $filename;
  29.  
  30. $sqlInsert2 = 'UPDATE noticias SET imagem = "' . $filename . '" WHERE idnoticia = "' . $lastId . '"';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement