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";
}
web Resource
  • 111
  • 1
  • 10
  • 2
    Possible duplicate of [Multiple file upload in php](http://stackoverflow.com/questions/2704314/multiple-file-upload-in-php) – Farshid Shekari Sep 06 '16 at 07: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. – web Resource Sep 06 '16 at 07:55
  • U can use foreach instead of for in php section of first answer that has 113 score. – Farshid Shekari Sep 06 '16 at 08: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. – web Resource Sep 06 '16 at 08:29
  • Hi tested it gives only lAST VALUE, CHECK MY QUESTION – web Resource Sep 06 '16 at 08:35
  • if possible can you see why my foreach is not showing all the image which i uploaded. rest of the things we discuss later. I want to understand step by step, because I am working as a tutor. – web Resource Sep 06 '16 at 08:54
  • I added another link for your problem. – Farshid Shekari Sep 06 '16 at 09:28

2 Answers2

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
}
Farshid Shekari
  • 2,391
  • 4
  • 27
  • 47
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

jandreu
  • 59
  • 1
  • 8