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

  • Home
  • SEARCH
  • 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 8563641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:00:22+00:00 2026-06-11T17:00:22+00:00

Here is the form form action=index.php method=POST enctype=multipart/form-data > <input type=file name=image[] multiple=multiple> <input

  • 0

Here is the form

form action="index.php" method="POST" enctype="multipart/form-data" >
        <input type="file" name="image[]" multiple="multiple">
        <input type="submit" value="upload">
    </form> 

I am trying to only run my code when only when if(!empty($_FILES['image'])){ but for some reason the array is not empty upon submitting no files and only clicking submit.

Here is the rest of the code if that will help, thanks.

<html>

Image Upload

    <form action="index.php" method="POST" enctype="multipart/form-data" >
        <input type="file" name="image[]" multiple="multiple">
        <input type="submit" value="upload">
    </form> 

    <?php

    include 'connect.php';

    if(!empty($_FILES['image'])){
    echo $_FILES['image']['error'];
        $allowed = array('jpg', 'gif', 'png', 'jpeg');
        $count = 0;

        foreach($_FILES['image']['name'] as $key => $name){
        $image_name = $name;
        $tmp = explode('.', $image_name);
        $image_extn = strtolower(end($tmp)); //can only reference file
        $image_temp = $_FILES['image']['tmp_name'][$count];
        $filesize = filesize($_FILES['image']['tmp_name'][$count]);
        $count = $count +1;

        if(count($_FILES['image']['tmp_name']) > 5){
            echo "You can upload a maximum of five files.";
            break;
        }

        else if(in_array($image_extn, $allowed) === false){
            echo $name." is not an allowed file type<p></p>";
        }

        else if($filesize > 1024*1024*0.3){
            echo $name." is too big, can be a maximum of 3MB";
        }

        else{

            $image_path = 'images/' . substr(md5($name), 0, 10) . '.' . $image_extn;


            move_uploaded_file($image_temp, $image_path);

            mysql_query("INSERT INTO store VALUES ('', '$image_name', '$image_path')") or die(mysql_error());

            $lastid = mysql_insert_id();
            $image_link = mysql_query("SELECT * FROM store WHERE id = $lastid");
            $image_link = mysql_fetch_assoc($image_link);
            $image_link = $image_link['image'];
            echo "Image uploaded.<p></p> Your image: <p></p><a href = $image_link>$image_path</a>";
            }

        }
        }

    else{
            echo "Please select an image.";
        }

    ?>

  • 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-11T17:00:24+00:00Added an answer on June 11, 2026 at 5:00 pm

    Use the is_uploaded_file PHP function instead:

    if(is_uploaded_file($_FILES['image']['tmp_name'])) {
      //code here
    }
    

    http://php.net/manual/en/function.is-uploaded-file.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form to upload image like below <form name=sample enctype=multipart/form-data action=index.php method=post
Files index.php <form name=postform action=post.php method=post enctype=multipart/form-data> <table class=postarea id=postarea> <tbody> <tr> <td class=postblock>Date:</td><td><input
Here is my form declaration <form enctype=text/plain method=post action=PI_Application_Submission.php> Here is my input: <tr><td>Requested
I created a login page using spring_security_check. Here: <form name='f' action=/sec_test/j_spring_security_check method='POST'> <table> <tr>
can anyone convert this code into the yii framework? file name: text.php <form method='POST'
I'm experiencing a very odd upload problem. Here's the relevant view file: <form action=http://localhost/index.php/temp/upload/
Here is a simple form I am using to send XML data in admin_xml.php
How to pass form data using POST method and JS submit() ? I would
I'm trying to send POST data to a test.php file, which handles POST data
I have this $data array: (built on a shell, not a form) (debugged here)

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.