首页 > 解决方案 > PHP move_uploaded_file() 不会将 3MB 的 .zip 上传到服务器

问题描述


我尝试使用 PHP 上传文件,并为此使用函数“move_uploaded_file()”。一切正常,直到我尝试上传压缩的 CSV 文件。文件本身为 50MB,但压缩后只有 3MB。我可以将文件上传到服务器,直到 5MB,所以对于 zip 文件,我认为这会起作用,但事实并非如此。

* 上传 100kb 的压缩 CSV 文件确实有效,
* 我确实从 CSV 文件中删除了 1/3 的行,CSV 文件为 28MB,我可以上传(压缩后为 1.6MB),
* 的压缩文件3MB 不会出现在服务器上的文件夹中。100KB 和 1.6MB 的压缩文件确实出现在那里,
* 我没有收到错误消息,但它确实显示“上传错误!”。

有人面临同样的问题,还是有人知道解决方案?让我知道!这基本上是我的代码;
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

if (isset($_POST["submit"])) {
    $file = $_FILES["file"];
    $filename = $file["name"];
    $target_dir = "data/";
    $target_file = $target_dir . basename($filename);
    $file_type = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

    if (move_uploaded_file($file["tmp_name"], $target_file)) {
        echo "Done uploading!";
    } else {
        echo "Error uploading!";
    }
}
?>

<form action="" method="post" enctype="multipart/form-data">
    <div class="custom-file mb-3">
        <input type="file" class="custom-file-input" id="file" name="file" required accept=".csv,.zip" />
    </div>
    <p class="text-right">
        <button class="btn btn-primary" name="submit" type="submit">Upload!</button>
    </p>
</form>


如果您需要什么,请告诉我。所有的帮助和想法都得到了认可。谢谢!


编辑;
我确实在 $_FILES['file']['error'];
我收到错误“1”,指的是:'上传的文件超出了 php.ini 中的 upload_max_filesize 指令'
https://www.php.net/manual/en/features.file-upload.errors.php

我做了“ echo phpinfo();",发现upload_max_filesize只有2MB,而不是我以为我配置的5MB。

标签: phpcsvuploadzipmove-uploaded-file

解决方案


推荐阅读