Multiple Image Upload PHP form with one input

0 votes

I want to have multiple image upload forms with only using one input.

The upload.php:

<?php
include("../include/session.php");

session_start();
$allowedExts = array("jpeg", "jpg", "png", "gif");
$extension = end(explode(".", $_FILES["upload"]["name"]));

if(isset($_FILES['upload']['tmp_name']))
{
    for($i=0; $i < count($_FILES['upload']['tmp_name']);$i++)
    {

        if (($_FILES["upload"]["name"] < 90000000000000000)
            && in_array($extension, $allowedExts)) {
                if ($_FILES["upload"]["error"] > 0)
                {
                    header('location: '.$error); die;
                }
                else
                {

                    if (file_exists("../icons/".$_SESSION["username"] ."/" . $_FILES["upload"]["name"]))
                    {
                    echo "error";
                    }
                    else
                    {
                        if(!is_dir("../icons/". $_SESSION["username"] ."/")) {
                            mkdir("../icons/". $_SESSION["username"] ."/");
                        }

                        $temp = explode(".",$_FILES["upload"]["name"]);
                        $file = rand(1,999999999999) . '.' .end($temp);

                        move_uploaded_file($_FILES["upload"]["tmp_name"], "../icons/". $_SESSION["username"] ."/". $file);  
                    }
                }
            }
        } else {
            echo "yep error";
        }
    }
} 
?>

If I take out the lines:

if(isset($_FILES['upload']['tmp_name']))
{
    for($i=0; $i < count($_FILES['upload']['tmp_name']);$i++)
    {

This works but only allows me to upload once. Can someone please guide me on making this work?

Jun 13, 2022 in PHP by narikkadan
• 63,600 points
607 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

How can I select and upload multiple files with HTML and PHP using HTTP POST?

Hello @kartik, This is possible in HTML5. Example (PHP ...READ MORE

answered Sep 15, 2020 in PHP by Niroj
• 82,840 points
2,014 views
0 votes
1 answer

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
3,371 views
0 votes
1 answer

Complete PHP form with proper validation and syntax

Hey @kartik, It's quite simple to have php ...READ MORE

answered Feb 19, 2020 in PHP by Niroj
• 82,840 points
1,561 views
0 votes
1 answer

MySQL - UPDATE multiple rows with different values in one query

Hello @kartik You can use a CASE statement to handle ...READ MORE

answered Jun 1, 2020 in PHP by Niroj
• 82,840 points
33,876 views
0 votes
1 answer

How can I upload Multiple file in php?

Hello @kartik, Multiple files can be selected and ...READ MORE

answered Aug 27, 2020 in PHP by Niroj
• 82,840 points
823 views
0 votes
1 answer

How to upload and Save Files with Desired name using php?

Hello, You can try this, $info = pathinfo($_FILES['userFile']['name']); $ext = ...READ MORE

answered Nov 4, 2020 in PHP by anonymous
• 82,840 points
9,703 views
0 votes
0 answers

PHP Merge 2 Images (Insert Face To An Image)

I have 2 images. one face image ...READ MORE

May 27, 2022 in PHP by Kichu
• 19,040 points
1,484 views
0 votes
0 answers

PHP5 - I want to write a Hindi text on image

I want to write Hindi text on ...READ MORE

May 27, 2022 in PHP by Kichu
• 19,040 points
739 views
0 votes
0 answers

Increase max_execution_time in PHP?

My server support post_max_size 192MB and max_execution_time 600 sec so when ...READ MORE

Jun 1, 2022 in PHP by Kichu
• 19,040 points
618 views
0 votes
0 answers

PHP upload image

I have a config.php file that connects ...READ MORE

Jun 4, 2022 in PHP by Kichu
• 19,040 points
518 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP