1

Here is my Form:

 <form action="" method="post"   enctype="multipart/form-data">
     <input  type="file" name="file[]" id="file" /> 
     <input type="submit" value="Upload Image" name="submit">
</form>

Here is my php:

 <?php
     $file=$_FILES['file']['name'];
     $dest="uploads/$file";
     $src=$_FILES['file']['tmp_name'];
     move_uploaded_file($src,$dest);
 ?>

How to use foreach after hitting the submit button? kindly guide me please.

MY FOR EACH GIVES ONLY ONE VALUE. I UPLOADED MORE THAN TWO IMAGE.iT SHOWS LAST ONE
foreach($_FILES['file']['name'] as $k=>$v)
{

echo "File : ", $_FILES['file']['name'][$k] ," is valid, and was                      successfully uploaded.\n";
}
7
  • 2
    Possible duplicate of Multiple file upload in php Commented Sep 6, 2016 at 7:52
  • not a problem kindly solve the issue. no for each was there. and it is not working, i tried, if u want , u please try. Commented Sep 6, 2016 at 7:55
  • U can use foreach instead of for in php section of first answer that has 113 score. Commented Sep 6, 2016 at 8:25
  • ok. I have used foreach only, my question is I am uploading more than two image at a time.In foreach how do i want to see those values, foreach($f as $k=>$v) { echo $v } like this how do I see my uploaded image, uploaded image is more than two.please test and give answer. Commented Sep 6, 2016 at 8:29
  • Hi tested it gives only lAST VALUE, CHECK MY QUESTION Commented Sep 6, 2016 at 8:35

2 Answers 2

1

Try this ...

foreach ($_FILES['image']['tmp_name'] as $key => $val ) {
    $filename = $_FILES['image']['name'][$key];
    $filesize = $_FILES['image']['size'][$key];
    $filetempname = $_FILES['image']['tmp_name'][$key];

    $fileext = pathinfo($fileName, PATHINFO_EXTENSION);
    $fileext = strtolower($fileext);

    // here your insert query
}
Sign up to request clarification or add additional context in comments.

Comments

0

hi your question seems incomplete but i'll try to answer

an a example to process

foreach($file as $oneFile){ mysql_query("INSERT INTO {{your table name}} VALUES ("+oneFile+")") }

but it work only if you have initialise a connexion to mysql

13 Comments

where to put print_r($onefile). I will upload three image at a time and i want to see ? what print_R says
put it here foreach($file as $oneFile){ echo($oneFile); mysql_query("INSERT INTO {{your table name}} VALUES ("+oneFile+")") } and use echo instead print_r cause print_R is for array and $oneFile is not an array
boss print_r($oneFile) gives only lastupload name., I uploaded two image at a time. let us see first print_r values
where have you put your print_r ? put in into the foreach
foreach($file as $oneFile){ print_r($oneFile); }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.