how upload multiple images using one form in php

how upload multiple images using one form in php?

Here am writing tutorial or php script code for inserting into database and uploading multiple images using single form or submit button you can use this code for uploading multiple images into the folder as well as database.
You just have need copy and past this code and use it..

PHP Code Here

<?php
//database connectivity
mysql_connect("localhost","root","")
mysql_select_db("images");

//php script for inserting into database and uploading multiple images using single form or submit button
if(isset($_POST['images']))
{
    $image1=$_FILES['image']['name'][0];
    $image1tmp=$_FILES['image']['tmp_name'][0];
    
    $image2=$_FILES['image']['name'][1];
    $image2tmp=$_FILES['image']['tmp_name'][1];
        
    $image3=$_FILES['image']['name'][2];
    $image3tmp=$_FILES['image']['tmp_name'][2];
        
    $image4=$_FILES['image']['name'][3];
    $image4tmp=$_FILES['image']['tmp_name'][3];

    move_uploaded_file($image1tmp, "word-images/$image1");
    move_uploaded_file($image2tmp, "word-images/$image2");
    move_uploaded_file($image3tmp, "word-images/$image3");
    move_uploaded_file($image4tmp, "word-images/$image4");
    
    mysql_query("INSERT INTO images (image1, image2, image3, image4) VALUES('$image1', '$image2', '$image3', '$image4')");
    echo "Your Images Insert Successfully !";
}

?>

When you write html script you have need one thing remember define name just a array type of your input type file field, because here we are uploading multiple files for more understanding you can use this html code and how we retrieve this file into php you can see php code.

Html Code Here

 <html>
    <head>
        <title>inserting into database and uploading multiple images using single form or submit button</title>
    </head>
<body>

<!-- Html Code Write here fror inserting into database and uploading multiple images using single form or submit button -->

<form method="post">
    <table border="1">
        <tr>
            <td width="166" height="34" align="left"  class="t11ft"><strong>Image 1</strong></td>
            <td colspan="2" align="left">
                <input type="file" name="image[]" id="image" />
            </td>
        </tr>
        <tr>
            <td width="166" height="34" align="left"  class="t11ft"><strong>Image 2</strong></td>
            <td colspan="2" align="left">
                <input type="file" name="image[]" id="image" />
            </td>
        </tr>
        <tr>
            <td width="166" height="34" align="left"  class="t11ft"><strong>Image 3</strong></td>
            <td colspan="2" align="left">
                <input type="file" name="image[]" id="image" />
            </td>
        </tr>
        <tr>
            <td width="166" height="34" align="left"  class="t11ft"><strong>Image 4</strong></td>
            <td colspan="2" align="left">
                <input type="file" name="image[]" id="image" />
            </td>
        </tr>
        <tr>
            <td width="166" height="34" align="left"  class="t11ft"><strong>Image 1</strong></td>
            <td colspan="2" align="left">
                <input type="submit" name="images" value="Insert Images" />
            </td>
        </tr>       
    </table>
</form>
</body>
</html>

Leave a Reply

Related Posts: You may like

Extract Total Number of Image And Missing Alt Attribute using php

How to extract Heading tags using PHP from string

How to remove whitespace from string using php

Remove All Special Characters From String PHP

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Download Instagram Videos & Photos.

Download Now

CURRENCY CONVERTER

Real Time Currency Converter

Convert Now

ROBOST.TXT GEN.

Robots.txt File Creater

Create Now

HTML MINIFIER

Compress yout HTML Code

Minify Now

CSS MINIFIER

Compress yout CSS Code

Minify Now

JAVASCRIPT MINIFIER

Compress yout JavaScript Code

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.