1

我正在尝试设置一个多图像上传器,每当我尝试上传超过 20 个文件时,只会上传前 20 个文件。

在我继续之前,我只想说 php.ini 中的 max_file_uploads 设置为 400,因此非常相似问题的其他答案似乎无法解决我的问题。

我的完整代码如下,请注意我知道我正在使用 mysql_query,但这仅用于本地测试目的。

-

PHP

if(isset($_POST['upload'])){
    include("SimpleImage.php");

    echo count($_FILES['file']['name']);

    for($i=0; $i<count($_FILES['file']['name']); $i++) {

        $allowedExts = array("gif", "jpeg", "jpg", "png", "JPG");
        $extension = end(explode(".", $_FILES["file"]["name"][$i]));

        date_default_timezone_set('Europe/London');
        $date = date_create();

        if ((($_FILES["file"]["type"][$i] == "image/gif")
        || ($_FILES["file"]["type"][$i] == "image/jpeg")
        || ($_FILES["file"]["type"][$i] == "image/jpg")
        || ($_FILES["file"]["type"][$i] == "image/png"))
        && ($_FILES["file"]["size"][$i] < 10485760)
        && in_array($extension, $allowedExts)){
            $name = date_timestamp_get($date) . "_" . mt_rand() . "." . $extension;

            if ($_FILES["file"]["error"][$key] > 0){
                $messages[] = "Return Code: " . $_FILES["file"]["error"][$i] . "<br>";
            }else{
                $imagethumbTrueLocation = "../../gallery/thumb/" . $name;
                $imagelargeTrueLocation = "../../gallery/photos/" . $name;

                $imagethumb = new SimpleImage();
                $imagethumb->load($_FILES["file"]["tmp_name"][$i]);
                $imagethumb->resizeToWidth(230);
                $imagethumb->save($imagethumbTrueLocation);

                $imagethumblocation = "thumb/" . $name;

                $imagelarge = new SimpleImage();
                $imagelarge->load($_FILES["file"]["tmp_name"][$i]);
                $imagelarge->resizeToWidth(800);
                $imagelarge->save($imagelargeTrueLocation);

                $imagelargelocation = "photos/" . $name;

                $queryresult = mysql_query("INSERT INTO gallery (thumbnail, highres) VALUES ('$imagethumblocation', '$imagelargelocation')") or die(mysql_error());
                if(!$queryresult) {
                    $messages[] = "Failed to insert record into the database.";
                }else{
                    $messages[] = "Record sucessfully added to the database.";
                }
            }
        }else{
            $messages[] = "Invalid file";
        }
    }

}

HTML

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

4 回答 4

1

我知道您提到了 max_file_uploads 但可能是 400 无法识别尝试 99 的情况吗?我说这是一个特定的数字 20 的唯一原因!每一次都必须有一个限度。你也检查过 apache 配置,那里也可能有限制

我会亲自使用 javascript 将它们关闭,因此每次上传都有自己的线程,可以这么说,如果有任何限制,您将能够绕过限制。

于 2013-10-07T10:19:11.763 回答
0

原来我的主机对此设置了自己的限制,这意味着只有 VPS 和专用帐户可以更改此值:(

于 2013-10-07T12:44:35.863 回答
0

如果您使用的是 Wamp,请转到 localhost 页面,然后单击 phpinfo(); 在左下角。如果没有,您可以在 php 文件中使用该函数。

你会看到:“Loaded Configuration File”栏,找到你的php.ini

因为有多个 php.ini(一个在 php 文件夹中,另一个在 apach 文件夹中)。完成后,您可以再次在 phpinfo() 中验证它,只需 CTRL + F 并查找“max_file_uploads”。

希望它会有所帮助。

于 2014-12-09T21:27:12.093 回答
0

打开 php.ini 配置文件并将 ; 可以通过单个请求上传的最大文件数 max_file_uploads = 更改为您希望 apache 在 POST 事件上处理的文件数。默认值为 20。

于 2017-11-07T14:08:06.987 回答