Uploading images of different inputs using PHP and MySQL

1

I'm developing a PHP system that will generate a folder to be placed in the shop window. My form is composed of some fields, among them, 4 <input> type file to upload a featured image and another 3 for galleria. I have created input's for separate uploads and not a multiple because I have fields in the database for each image to make it easier to view. My question is: how do I recover these images and record them in BD? So far, I have idea how to do with one, but not with several.

Mybackend:

<?phpinclude_once'config/conn.php';$imagemDestaque=$_FILES["imagemDestaque"];
$textoDestaque  = $_POST["textoDestaque"];
$valor          = $_POST["valor"];
$referencia     = $_POST["referencia"];
$descricao      = $_POST["descricao"];
$galeria1       = $_FILES["galeria1"];
$galeria2       = $_FILES["galeria2"];
$galeria3       = $_FILES["galeria3"];

foreach ($_FILES as $file){
    if($imagemDestaque != NULL) { 
        $nomeFinal = $file['namevb '];
        if(move_uploaded_file($imagemDestaque['tmp_name'], $nomeFinal)) {
            $tamanhoImg = filesize($nomeFinal); 

            $mysqlImg = addslashes(fread(fopen($nomeFinal, "r"), $tamanhoImg));

            try{
            $sql = "INSERT INTO himoveis VALUES (:imagemDestaque,:textoDestaque, :valor, :referencia, :descricao, :galeria1, :galeria2, :galeria3)";
            $q = $conn->prepare($sql);
            $q->execute(array(
                ':imagemDestaque'   =>$imagemDestaque,
                ':textoDestaque'    =>$textoDestaque,
                ':valor'            =>$valor,
                ':referencia'       =>$referencia,
                ':descricao'        =>$descricao,
                ':galeria1'         =>$galeria1,
                ':galeria2'         =>$galeria2,
                ':galeria3'         =>$galeria3
                ));

                echo $sql->rowCount();
            }       
            catch(PDOException $e) {
            echo 'Error: ' . $e->getMessage();

            unlink($nomeFinal);

            header("location:exibir.php");
            }

        }else { 
            echo"Você não realizou o upload de forma satisfatória."; 
        }
    }
}
?>
    
asked by anonymous 20.05.2015 / 15:30

0 answers