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

Your email address will not be published. Required fields are marked *

Related Posts: You may like

All Full Forms Related to Database

How to login with LinkedIn oAuth2 in PHP

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

comma separated values in mysql query

SQL statement to retrieve names beginning with A

Redirecting HTTP to HTTPS with PHP

Convert Base64 string to an image file

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Free online tool to download Instagram videos, photos and save Instagram videos, photos to your device. It's free & easy to use.

Download Now

CURRENCY CONVERTER

Our real time currency converter calculator will convert your money based on current values from around the world. It's free & easy to use.

Convert Now

ROBOST.TXT GEN.

Create robots txt file that help search engines to crawling and indexing your site with help of our free online Robots.txt Generator tool.

Create Now

HTML MINIFIER

Free online tool to minify or compress html code and reduce the size of html code in few clicks. It's free & easy to use.

Minify Now

CSS MINIFIER

Free online tool to minify or compress css code and reduce the size of css code in few clicks. It's free & easy to use.

Minify Now

JAVASCRIPT MINIFIER

Free online tool to minify or compress javascript code and reduce the size of javascript code in few clicks. It's free & easy to use.

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.