Image Upload saved only first image in the database

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 the images in the upload directory are saved, but when sending to the database only the first one selected is registered.

    
asked by anonymous 19.06.2015 / 12:07

1 answer

2

You are using the same ID to insert all images. I understand that this is what you want, to associate all images with the same record, but is your DDL prepared for it? Two inserts for the same ID on this table will not violate some constraint? This would explain the entry of a record, but no more.

    
19.06.2015 / 12:12