You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP使用move_uploaded_file()无法上传3MB大小zip压缩包问题咨询

PHP ZIP文件上传失败问题排查

我尝试使用PHP的move_uploaded_file()函数实现文件上传功能,此前功能运行正常,直到上传CSV文件的ZIP压缩包时出现问题:原CSV文件大小为50MB,压缩后ZIP包仅3MB,我原本认为服务器支持最大5MB文件上传,该压缩包应该可以正常上传,但实际上传失败。

已做验证测试

  • 大小为100KB的CSV压缩ZIP包可正常上传;
  • 删除原CSV文件1/3的内容,得到28MB的CSV文件,压缩后ZIP包大小为1.6MB,可正常上传;
  • 大小为3MB的ZIP包上传后不会出现在服务器指定目录中,100KB、1.6MB的ZIP包均可正常出现在目标目录;
  • 上传时没有抛出明确报错,仅页面输出“Error uploading!”。

核心实现代码

<?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配置项的限制
执行phpinfo()查看配置后确认,upload_max_filesize实际仅为2MB,并非我之前误以为的5MB,这是3MB文件上传失败的根本原因。

内容的提问来源于stack exchange,提问作者Antonio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 21:06:04