Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:35:30+00:00 2026-06-13T01:35:30+00:00

I am new in php and I am trying to make a multiple image

  • 0

I am new in php and I am trying to make a multiple image uploader. My form looks like this:

<form action="" method="post" enctype="multipart/form-data">
    <p class="style2">Izberi datoteko: <br /><input type="file" name="image" multiple="multiple" /></p>
    <p class="style2">
        Izberi Album: <br />
            <select name="album_id">
                <?php 
                    foreach ($albums as $album) {
                        echo '<option value="', $album['id'] ,'">', $album['name'] ,'</option>';
                    }
                ?>
            </select>
    </p>
    <p class="style2"><input type="submit" value="Naloži Slike" /></p>
</form>

And on the php side I did something like:

if (isset($_FILES['image'], $_POST['album_id'])) {
$image_name = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_temp = $_FILES['image']['tmp_name'];

$allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
$a = explode('.', $image_name);
$image_ext = strtolower(end($a));

$album_id = $_POST['album_id'];

$errors = array();

if (empty($image_name) || empty($album_id)) {
    $errors[] = '<p class="style2">Nekaj manjka!</p>';
} else {

    if (in_array($image_ext, $allowed_ext) === false) {
        $errors[] = '<p class="style2">Izbrani tip datoteke ni dovoljen!</p>';
    }

    if ($image_size > 2097152) {
        $errors[] = '<p class="style2">Izbrana datoteka je prevelika! Maksimalna velikost datoteke mora biti 2mb!</p>';
    }           
}

if (!empty($errors)) {
    foreach ($errors as $error) {
        echo $error;
    }
} else {
    upload_image($image_temp, $image_ext, $album_id);
    header('Location: view_album.php?album_id='.$album_id);
    exit();
} 

}

I created a function that puts the image into database. This function looks like this:

function upload_image($image_temp, $image_ext, $album_id) {
$album_id = (int)$album_id;

mysql_query("INSERT INTO `images` VALUES ('', '". $_SESSION['user_id'] ."', '$album_id', UNIX_TIMESTAMP(), '$image_ext')"); 

$image_id = mysql_insert_id();
$image_file = $image_id.'.'.$image_ext;
move_uploaded_file($image_temp, 'galerija/'.$album_id.'/'.$image_file);

create_thumb('galerija/'.$album_id.'/', $image_file, 'galerija/thumbs/'.$album_id.'/');
}

This works fine for uploading only one image. I tried to create a form for multiple select files and i can select more images but in database only gets first image. I tried to put foreach() in my script but I don t know where and how I must put it in.
So how can i change my script so I can upload more images into my database? I just can’t figure it out. Any help would be great!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:35:30+00:00Added an answer on June 13, 2026 at 1:35 am

    A. PHP would not be albe to see your multiple files like that

    Replace

      <input type="file" name="image" multiple="multiple" />
    

    With

     <input type="file" name="image[]" multiple="multiple" />
    

    To loop over this files you need something like

    foreach ( $_FILES['image']['tmp_name'] as $key => $val ) {
    
        $fileName = $_FILES['image']['name'][$key];
        $fileSize = $_FILES['image']['size'][$key];
        $fileTemp = $_FILES['image']['tmp_name'][$key];
    
        $fileExt = pathinfo($fileName, PATHINFO_EXTENSION);
        $fileExt = strtolower($fileExt);
    
        // Continue
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a non-WSDL call in PHP (5.2.5) like this. I'm sure
I'm new in PHP and I'm trying to make an image validation with TYPE
I am pretty new to PHP and I am trying to make an inventory
I am trying to use a PHP form (new.php) to update 2 MySQL tables
I am new to php and I am getting this error trying to load
I am new to PHP and JavaScript development, I am trying to execute this
i'm new related to creating php class's and objects... I'm trying to make a
I new to PHP. I'm trying to make an Incidence of Coincidence (IC) calculator
I'm trying to make a message board with php, but when a new message
hello im trying to make something like github treeslider im new to javascript.. but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.