如果所选图像的数量超过10,则无法上传所选图像

时间:2016-04-12 19:50:41

标签: php

我编写了一个代码,用于在特定位置上传图像并显示一些上传的图像计数。当我选择低于8张图像时,它将完美地工作。但是,如果我选择10到20张图像,则相同的代码无效。我真的不知道为什么它在选择最小数量的图像时会起作用而在我选择大量图像时不起作用。请找到我的以下代码

storeimage.php

 <?php
    require_once 'pdoconnectionusingclass.php';
?>
<html lang="en">
    <head>
      <meta charset="UTF-8" />
      <title>Multiple File Ppload with PHP</title>
    </head>
    <body>
      <form action="storeimagename.php" method="POST" enctype="multipart/form-data">
          <div>
          <select name="moviename">
          <option value = "">---Select---</option>
          <?php
          try
          {
            $dbobj=new database();
            $dbobj->openconnection();
            $sql='select * from tbl_movie';
            $query=$dbobj->getdata($sql);
            if(isset($query))
            {
                foreach ($query as $row)
                {
                    echo '<option value='.str_replace(' ','_', $row['movie_name']).'>'.$row['movie_name'].'</option>';
                }   
            }
            $dbobj->closeconnection();
          }

          catch(Exception $e)
          {
              echo $e->getMessage();
          }
          ?>
          </div>
          <br/>
          <div>
            <input type="file" id="file" name="files[]" multiple="multiple" accept="image/*" />
            <input type="submit" value="Upload!" />
          </div>
    </form>
    </body>
    </html>

storeimagename.php

<?php
require_once 'pdoconnectionusingclass.php';
$valid_formats = array("jpg", "png", "gif", "bmp");
$max_file_size =  1048576 *10; //100 kb
$path = "uploads/"; // Upload directory
$count = 0;

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
    // Loop $_FILES to exeicute all files


    $total_image=count($_FILES['files']['name']);

    $dbobj=new database();
    $dbobj->openconnection();

    for($i=0;$i<$total_image;$i++)
    {
    foreach ($_FILES['files']['name'] as $i => $name) {     
        if ($_FILES['files']['error'][$i] == 4) {
            continue; // Skip file if any error found
        }          
        if ($_FILES['files']['error'][$i] == 0) {              
            if ($_FILES['files']['size'][$i] > $max_file_size) {
                $message[] = "$name is too large!.";
                continue; // Skip large files
            }
            elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
                $message[] = "$name is not a valid format";
                continue; // Skip invalid file formats
            }
            else{ // No error found! Move uploaded files 
//                    echo $_FILES['files']['tmp_name'][$i];
//                    echo $_FILES['files']['name'][$i];

                    if(move_uploaded_file($_FILES["files"]["tmp_name"][$i], $path.$name))
                    {
                        $count++; // Number of successfully uploaded file
                        $gallery.=','.$name;

                    }
            }
        }
    }
    }

    if(count==18)
    {
         $sql='insert into tbl_movie_gallery values((select movie_id from tbl_movie where movie_name='.str_replace('_',' ',$_POST['moviename']).')'.$gallery.');';
         $dbobj->insertdata($sql);
    }

    //unset($_FILES['files']);
    $dbobj->closeconnection();
}
?>

程序在执行$ total_image = count($ _ FILES ['files'] ['name'])时终止;如果我选择10到20个文件。 $ total_image显示计数为0.任何人都可以帮助解决问题是什么?提前致谢。

1 个答案:

答案 0 :(得分:1)

PHP提供了一次可以上传的最大文件数量的设置。默认值为20.您需要在php.ini文件中更改此内容。

您正在寻找的设置是max_file_uploads

More information