Uploading multiple images one to each row PHP and Mysqli db

James Allan

I have 3 images to upload in my form.

    <form action="" method="post" enctype="multipart/form-data" class="form-horizontal">
   <div class="form-group col-md-5">
     <label for="image">Centralizada</label>
       <input id="image" type="file" name="image" class="btn btn-danger">
     </div>

    <div class="form-group col-md-5">
     <label for="img_v1">V1</label>
       <input id="img_v1" type="file" name="img_v1" class="btn btn-danger">
    </div>

   <div class="form-group col-md-5">
      <label for="img_v2">V2</label>
        <input id="img_v2" type="file" name="img_v2" class="btn btn-danger">
   </div>.

And i have these three rows in my database: image, img_v1, img_v2

And i want to upload all the 3 images to each row but my script is not working. Its posting only the first image and the other two is not.

this is my script

<?php 
include("includes/dbconn.php");


    $error = ''; 
    if(isset($_POST['submit_post'])){
    $title = strip_tags($_POST['title']);
     $date = date('Y-m-d h:i:s');
    if($_FILES['image']['name'] !=''){
    $image_name = $_FILES['image']['name']; 
    $image_tmp = $_FILES['image']['tmp_name'];
    $image_size = $_FILES['image']['size'];
    $image_ext = pathinfo($image_name,PATHINFO_EXTENSION);
     $image_path = '../clientes/img/'.$image_name;
    $image_db_path = 'img/'.$image_name;
    if($image_size < 10000000){
    if($image_ext == 'jpg' || $image_ext == 'png' || $image_ext == 'jpeg' ||     $image_ext == 'gif'){
   if(move_uploaded_file($image_tmp,$image_path)){
  $ins_sql = "INSERT INTO gallery (title, description, image, img_v1,  img_v2, category, status) VALUES ('$title', '$_POST[description]',
   '$image_db_path', '$image_db_path', '$image_db_path', '$_POST[category]',   '$_POST[status]')";

Why my other images is now uploading? Obs:im learning php -noob

cmnardi

Try this (I have not tested)

function imageUpload($field)
{
    $image_name = $_FILES[$field]['name'];
    $image_tmp = $_FILES[$field]['tmp_name'];
    $image_size = $_FILES[$field]['size'];
    $image_ext = pathinfo($image_name, PATHINFO_EXTENSION);
    $image_path = '../clientes/img/' . $image_name;
    if ($image_size < 10000000) {
        if ($image_ext == 'jpg' || $image_ext == 'png' || $image_ext == 'jpeg' || $image_ext == 'gif') {
            return move_uploaded_file($image_tmp, $image_path);
        }
    }
    return false;
}



if (isset($_POST['submit_post'])) {
    $title = strip_tags($_POST['title']);
    $date = date('Y-m-d h:i:s');
    if ($_FILES['image']['name'] != '') {

        $upload = imageUpload('image');
        $image_db_path = 'img/' . $_FILES['image']['name'];
        $upload1 = imageUpload('img_v1');
        $image_db_path1 = 'img/' . $_FILES['img_v1']['name'];
        $upload2 = imageUpload('img_v2');
        $image_db_path2 = 'img/' . $_FILES['img_v2']['name'];

        if ($upload && $upload1 && $upload2)
        $ins_sql = "INSERT INTO gallery (title, description, image, img_v1,  img_v2, category, status) VALUES ('$title', '$_POST[description]',
'$image_db_path', '$image_db_path1', '$image_db_path2', '$_POST[category]',   '$_POST[status]')";

    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiple images rename & uploading in PHP

From Dev

Multiple images rename & uploading in PHP

From Dev

PHP: Uploading multiple images to imgur at once

From Dev

PHP: Uploading multiple images at the same time

From Dev

Uploading multiple images in webservice using PHP

From Dev

only one record is saving when uploading multiple images in yii

From Dev

Uploading multiple image fields to each row in server mysql

From Dev

Uploading multiple images with volley?

From Dev

Uploading multiple images in codeigniter?

From Dev

Uploading multiple images with paperclip?

From Dev

Uploading multiple images with Django

From Dev

Uploading multiple images in codeigniter?

From Dev

Django multiple images not uploading

From Dev

multiple mysqli delete codes on one PHP page

From Dev

All images in one single row, or all images below each other

From Dev

select one radio button from each row and then submit it to database mysqli

From Dev

Magento Product Import With Multiple Images IN ONE ROW

From Dev

How to separate php mysqli result by limit each 4 result in a row

From Dev

mysqli query returns the column name as one row in php

From Dev

Uploading Multiple Images using CarrierWave

From Dev

PHP mysqli fetch_row - iterate over multiple records

From Dev

In multiple files upload(PHP/Mysql), the images are stored in single column. Want to store each image in single row with same id

From Dev

All images not uploading in multiple images upload

From Dev

Unique id for each row in mysqli

From Dev

Wont uploading bigger images PHP

From Dev

PHP: Images file is not uploading on the server?

From Dev

PHP MySqli Multiple query & while in one page - help to simplifying code

From Dev

Creating multiple while loops for one array in php and mysqli

From Dev

PHP MySQLi - update multiple data with some formula in one process

Related Related

  1. 1

    Multiple images rename & uploading in PHP

  2. 2

    Multiple images rename & uploading in PHP

  3. 3

    PHP: Uploading multiple images to imgur at once

  4. 4

    PHP: Uploading multiple images at the same time

  5. 5

    Uploading multiple images in webservice using PHP

  6. 6

    only one record is saving when uploading multiple images in yii

  7. 7

    Uploading multiple image fields to each row in server mysql

  8. 8

    Uploading multiple images with volley?

  9. 9

    Uploading multiple images in codeigniter?

  10. 10

    Uploading multiple images with paperclip?

  11. 11

    Uploading multiple images with Django

  12. 12

    Uploading multiple images in codeigniter?

  13. 13

    Django multiple images not uploading

  14. 14

    multiple mysqli delete codes on one PHP page

  15. 15

    All images in one single row, or all images below each other

  16. 16

    select one radio button from each row and then submit it to database mysqli

  17. 17

    Magento Product Import With Multiple Images IN ONE ROW

  18. 18

    How to separate php mysqli result by limit each 4 result in a row

  19. 19

    mysqli query returns the column name as one row in php

  20. 20

    Uploading Multiple Images using CarrierWave

  21. 21

    PHP mysqli fetch_row - iterate over multiple records

  22. 22

    In multiple files upload(PHP/Mysql), the images are stored in single column. Want to store each image in single row with same id

  23. 23

    All images not uploading in multiple images upload

  24. 24

    Unique id for each row in mysqli

  25. 25

    Wont uploading bigger images PHP

  26. 26

    PHP: Images file is not uploading on the server?

  27. 27

    PHP MySqli Multiple query & while in one page - help to simplifying code

  28. 28

    Creating multiple while loops for one array in php and mysqli

  29. 29

    PHP MySQLi - update multiple data with some formula in one process

HotTag

Archive