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 8600909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:43:23+00:00 2026-06-12T01:43:23+00:00

I wrote this code but I have an problem. I can not verify if

  • 0

I wrote this code but I have an problem. I can not verify if there is no file uploaded when anyone hit submit and I can not specific the allowed extinsion for example “.jpg”. How can I do this in “foreach”, I can do this when I upload just one image but this code for multi upload and if have you noticed i have used array in the form.

<?php 
mysql_connect('localhost','root','root')or die (mysql_error());
mysql_select_db('storeimage');
?>
<?
if ($_POST['submit'] ){
  $file=$_FILES['file'];
  $name=$_FILES['file']['name'];
  $tmp_name=$_FILES['file']['tmp_name'];

  foreach($name as $key=>$value){
    $name_file=$name[$key];
    $tmp_file=$tmp_name[$key];
    $imgpath = rand().'.jpeg'; 

    move_uploaded_file($tmp_file,'images/'.$imgpath);

    $insert=mysql_query("insert into  imagelocation values('','images/$imgpath')")or die (mysql_error());
    $id=mysql_insert_id();

    $select=mysql_query("select * from  imagelocation where id='$id' ");

    while ($row=mysql_fetch_object($select)){
      echo "<center><img src='$row->images'/></center><br/>";
    }
  }
}
?>
<form action='' method='post' enctype='multipart/form-data'>
<input type='file' name='file[]' multiple />
<input type='submit' name='submit'/>
</form>
  • 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-12T01:43:24+00:00Added an answer on June 12, 2026 at 1:43 am

    You work with multiple files you need to do something like this

    $allowedExt  = array("jpg");
    if (isset($_FILES['file'])) {
        foreach ( $_FILES['file']['tmp_name'] as $key => $file ) {
            if ($_FILES["file"]["error"][$key] == UPLOAD_ERR_OK) {
                $fileName = $_FILES['file']['name'][$key];
                $fileSize = $_FILES['file']['size'][$key];
                $fileTemp = $_FILES['file']['tmp_name'][$key];
                $fileType = $_FILES["file"]["type"][$key];
                $fileExt = pathinfo($fileName, PATHINFO_EXTENSION);
                $fileExt = strtolower($fileExt);
    
                if(!in_array($fileExt, $allowedExt))
                {
                    // extention not supported ;
                    continue;
                }
    
                // do your magic
    
    
    
            } else {
                // Somethign bad happend 
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to fix a glitch with this code someone wrote but I'm not
I have this code to write to a file, it works perfect but I
I have this code to update users data, but I can't write the for
Im new to ruby, wrote this code and works but i know is not
I have write this code but it does work only if I am already
I wrote this code for zoom in/out . it works but even with one
I wrote this code. The constructor works normally, but in the destructor I get
My brother wrote this code for me to show an example of polymorhism. But
I wrote this little code std::map<int,template<class T>> map_; map_.insert(make_pair<int,message>(myMsg.id,myMsg)); but the compiler doesn't seem
I've write this code to add textview into table row, but I've problem for

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.