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

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

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

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.