我正面临与PHP文件上传相关的问题.我正在尝试使用AJAX提交表单.此ajax请求包含文本变量和文件.当我尝试仅发送一个文件时,则一切正常,但是如果我要发送多个文件.我收到 413请求实体太大错误.我正在使用Apache.这是我的代码
I am facing a problem which is related to PHP file upload . I am trying to submit a form using AJAX . This ajax request contains text variables and file(s) . When I am trying to send only one file then everything is going okay but in case I am sending more than one file. I am getting 413 Request Entity Too Large error . I am using Apache . Here is my code
const data = new FormData(); data.append('name', 'my upload file'); for (const i = 1; i <= 4; i++) { const img = $(`#src${i}`).find('img').attr('src'); data.append(`image${i}`, img || ''); } $.ajax({ type: "POST", url: "server.php", data: data, cache: false, processData: false, contentType: false, success: (result) => { console.log(1); } });我所有上传的文件都小于700KB,我还使用ini_get_all()检查了PHP配置,发现post_max_size为48MB,upload_max_filesize为32MB.我不明白是什么原因造成了这个问题.
All my uploaded files are lesser than 700KB , I also checked the PHP configuration using ini_get_all() and I found that post_max_size is 48MB , upload_max_filesize is 32MB . I am not getting that what is the reason for that problem .
要检查我是否超出了允许的上传限制,我添加了四个文件(每个文件大小为10KB),但是当我能够发送一个400KB的文件时,它也会产生相同的问题.有什么方法可以确定此问题的根本原因.
To check that whether I am exceeding the allowed upload limit , I added four files (each with 10KB) but it also generating same problem while I am able to send one file of 400KB . Is there any way to identify the root cause of this problem.
推荐答案您需要将您的nginx conf(/usr/local/nginx/conf/nginx.conf)设置更改为此
You need to change your nginx conf (/usr/local/nginx/conf/nginx.conf) setting to this
client_max_body_size 512M;//set it to higher mb设置此值后,您需要重新启动Nginx
After setting this value you would need to restart nginx
service nginx restart更多推荐
(413)文件上传PHP期间请求实体太大错误
发布评论