PHP implementation of multiple image upload program code

Source: Internet
Author: User

In doing picture upload used to symfony third-party upload Library, see Symfony2 use Third-party library upload production picture upload "original", but for many pictures upload how to deal with, here I used a stupid way is to convert multiple images array into a single image array upload!

The form is submitted as follows:


The array of accepted picture information is as follows:

So do some processing of this, a single picture is uploaded in turn, as follows:

If (isset $_files[' image ') &&  $_files[' image '] [' name ']] {
  $file = $_files[' image '];
& nbsp $num = count ($_files[' image '] [' name ']); Calculate the number of uploaded pictures
 /processing array
  for ($i =0 $i < $num; $i + +) {
    $data [$i] [' name '] = $file [ ' Name ' [$i];
    $data [$i] [' type '] = $file [' type '] [$i];
    $data [$i] [' tmp_name '] = $file [' Tmp_name '] [$i];
    $data [$i] [' error '] = $file [' ERROR '] [$i];
    $data [$i] [' size '] = $file [' Size '] [$i];
 }
  foreach ($data as $key => $val) {
    $_files[' image ' = $val;
  
&nb sp;  if (move_uploaded_file ($val [' name '], './', $val [' name ']) {
        Echo ' ";
   }else{
        Echo is out of error! ';
   }

}
$info [' image '] = serialize ($img); Serializing an array of stored databases
$conn->insert (' Maintenance ', $info);
}

This is a more lazy approach, there are wrong places also look for more advice!

Note: fileupload (' image ') is an upload class, you can refer down to see Move_uploaded_file ($value, $savepath);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.