Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)


文件上传异常解决方案

异常信息:Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)

-----------------------

服务器:Windows IIS
语言环境:PHP-7.2.33-nts-Win32-VC15-x64

-----------------------

解决方案如下:

-----------------------

一、设置 php.ini

PHP可能消耗的最大内存量。
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 1024M

PHP将接受的POST数据的最大大小。
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 1024M


; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
;upload_tmp_dir =
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize. default 200M
upload_max_filesize = 512M

通过单个请求允许上传的文件数量,例如用户每次最多只能上传50个文件或图片。
; Maximum number of files that can be uploaded via a single request
max_file_uploads = 50

大小优先级:memory_limit >= post_max_size >= upload_max-filesize
-----------------------

二、设置 web.config 中设置 512MB。
<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="536870912"></requestLimits>
        </requestFiltering>
    </security>
</system.webServer>

上一篇:2021-7-15 Maximum Element After Decreasing and Rearranging


下一篇:[Leetcode学习-java]Maximum Length of Repeated Subarray