使用 PHP 和 HTML 输入标签上传 200 多张图片


upload more than 200 images using php and html input tag

我正在尝试在php中上传多个图像文件.我编辑了php.ini并将upload_max_files设置为20000.但它一次只能上传200张图像。

这是我的代码

if(isset($_FILES['files'])){ $count=0; foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name){
    $target="upload/photo/";
    $target=$target.$_FILES['files']['name'][$key];
    $partphoto = substr("$target", 13, -4);
    $qq="select * from idol_student_photo where name='$partphoto'";
    $res=mysql_query($qq);
    $row=mysql_fetch_array($res);
    if(file_exists($target))
    {
    echo $_FILES['files']['name'][$key]." already exists in photo folder <br />";
    }
    else if($row['name'])
    {
    echo $partphoto." already exists database <br />";
    }
    else
    {
        if(move_uploaded_file($tmp_name, $target)){
            //$id = mysql_insert_id($con);

            mysql_query("INSERT INTO tablename VALUES ('$partphoto')");
            $count=$count+1;
        }
        }
}


            echo "<center>".$count."file uploaded</center>";
            }

这可能是 PHP 的限制。所以我们真的无法帮助你。然而;大多数PHP系统都有zip功能。因此,请检测客户端验证中的图片是否过多,并建议用户使用 zip 方法。我还没有测试过这段代码,但应该让你朝着正确的方向前进!

$zip = zip_open("/tmp/youruploaded.zip");
$target="upload/photo/";
if ($zip) {
    while ($zip_entry = zip_read($zip)) {

        $zipfilename = zip_entry_name($zip_entry);
        $target=$target.$zipfilename;
        $partphoto = substr("$target", 13, -4);
        $qq="select * from idol_student_photo where name='$partphoto'";
        $res=mysql_query($qq);
        $row=mysql_fetch_array($res);
        if(file_exists($target)) {
            echo $zipfilename." already exists in photo folder <br />";
        } else if($row['name']) {
            echo $zipfilename." already exists database <br />";
        } else{
        $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
            if (file_put_contents($target, $buf)) {
                mysql_query("INSERT INTO tablename VALUES ('$partphoto')");
                $count=$count+1;
            } else {
                echo 'can''t put picture';
            }
        }
    }
    zip_close($zip);
}

祝你好运