无法 POST 形成 max_filesize

Unable to POST form with max_filesize

上传文件正常,文件大小小于 2.9 MB,但我的 phpinfo (localhost) 显示 upload_max_filesize 64M.

尝试上传较大的文件时,表单提交后 $_POST 为空且没有上传文件。

这是我的代码:

        <?php
            function fileUpload($attachment){
                $target_file = UPLOADDIR.basename($attachment["name"]);
                if (file_exists($target_file)) {
                    return "Sorry, file already exists.";
                }
                if (move_uploaded_file($attachment["tmp_name"], $target_file)) {
                    return "The file ". basename( $attachment["name"]). " has been uploaded.";
                } else {
                    return $attachment;
                    return "Sorry, there was an error uploading your file.";
                }
            }
            if(isset($_POST["submit"])) {
                fileUpload($_FILES['fileToUpload'])
            }
        ?>

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
            Select image to upload:
            <input type="file" name="fileToUpload" id="fileToUpload">
            <input type="submit" value="Upload Image" name="submit">
        </form>

在上传脚本之前,您可以在 php 代码中设置最大上传大小

ini_set('upload_max_filesize', '10M');

或 您需要在 php.ini 中设置 upload_max_filesize 和 post_max_size 的值:

; Maximum allowed size for uploaded files.
upload_max_filesize = 40M

; Must be greater than or equal to upload_max_filesize
post_max_size = 40M

在那之后 运行 你的代码

ini_set('max_execution_time', 300); //300 seconds = 5 minutes

把它放在你的 PHP 脚本的顶部,让你的脚本松散!

如果您进行了任何更改或修改 php.ini 个文件,您需要重新启动 HTTP 服务器(或本地主机)以使用新配置。