1
I have the following image upload code
if(isset($_POST['upload'])){
//INFO IMAGEM
$file = $_FILES['img'];
$numFile = count(array_filter($file['name']));
//PASTA
$folder = 'upload';
if($numFile <= 0)
echo 'Selecione uma Imagem!';
else{
for($i = 0; $i < $numFile; $i++){
$name = $file['name'][$i];
$type = $file['type'][$i];
$size = $file['size'][$i];
$tmp = $file['tmp_name'][$i];
$extensao = @end(explode('.', $name));
$novoNome = rand().".$extensao";
$identificador = $_POST['EdicaoId'];
$UrlImagem = $folder.'/'.$novoNome;
if(move_uploaded_file($tmp, $folder.'/'.$novoNome)){
$SalvaUrl = $conn->prepare("INSERT INTO revistas (id,url) VALUES (:id,:url)");
$SalvaUrl->bindParam(':id',$identificador);
$SalvaUrl->bindParam(':url',$UrlImagem);
$SalvaUrl->execute();
}}}}
Only images are saved in the upload directory, but when uploading to the database only the first one selected is registered.
thank you very much was this, the ID was set as the primary key.
– wwwjsw