简体   繁体   English

使用PHP脚本上载图像失败

[英]Uploading Images with PHP Script Failing

I'm fairly new to PHP, but I'm having a recurring issue via multiple different scripts and servers when uploading images via ShareX to my server with a custom script, specifically this one . 我对PHP很新,但是当我使用自定义脚本将图像通过ShareX上传到我的服务器时,我通过多个不同的脚本和服务器遇到了一个反复出现的问题,特别是这个

I've migrated servers (I was on a shared host, now I'm on a VPS), and have since changed to using this script, but I'm still having the issue and I don't know what exactly the problem is. 我已经迁移了服务器(我在共享主机上,现在我正在使用VPS),并且已经改为使用这个脚本,但我仍然遇到问题,我不知道究竟是什么问题。

The issue (does not occur 100% of the time, but it does most of the time; sometimes it works after retrying) is that uploading images over a certain size, about 250-500KB times out or fails most of the time. 问题(100%的时间没有发生,但大部分时间都在发生;有时它在重试后有效)是上传超过一定大小的图像,大约250-500KB次或大部分时间失败。 After 60 seconds, I get a 502 error (Bad Gateway) on ShareX. 60秒后,我在ShareX上收到502错误(Bad Gateway)。

I've looked up common solutions to similar problems ("large" files timing out in PHP), and have checked the following variables in my PHP.ini file. 我查找了类似问题的常见解决方案(PHP中的“大”文件超时),并在我的PHP.ini文件中检查了以下变量。

max_execution_time = 60
max_input_time = 60
memory_limit = 128M
post_max_size = 8M

When uploads are successful, it takes a few seconds in total to upload and get the link of the uploaded image returned, but when it fails, it's always 60 seconds and then error. 上传成功后,上传总共需要几秒钟,并返回上传图片的链接,但是当它失败时,它总是60秒,然后是错误。 There is no middle ground, it's either it succeeds instantly or times out after 60 seconds. 没有中间立场,它要么立即成功,要么在60秒后超时。

I don't know exactly how to go about finding what exactly the error (if any) is. 我不确切知道如何找到错误的确切内容(如果有的话)。 When it happens, ShareX reports a (502) Bad Gateway error, the 'Response:' is just the source code of the page (the script is set up to redirect you to this page if it detects you aren't uploading anything or it fails), and the 'Stack Trace' is the following: 当发生这种情况时,ShareX报告(502)错误网关错误,“响应:”只是页面的源代码(如果脚本检测到您没有上传任何内容或脚本,则将其设置为将您重定向到此页面失败),'Stack Trace'如下:

StackTrace: 堆栈跟踪:

at System.Net.HttpWebRequest.GetResponse()
   at ShareX.UploadersLib.Uploader.UploadData(Stream dataStream, String url,     String fileName, String fileFormName, Dictionary`2 arguments,     NameValueCollection headers, CookieCollection cookies, ResponseType responseType, HttpMethod method, String requestContentType, String metadata)

Edit: My server is behind cloudflare, and I read that cloudflare might cause problems. 编辑:我的服务器落后于cloudflare,我读到cloudflare可能会导致问题。 However, I've checked the settings and the maximum upload size is set at 100MB on cloudflare, and pausing it doesn't seem to help. 但是,我已经检查了设置,并且cloudflare上的最大上传大小设置为100MB,暂停它似乎没有帮助。

Edit: I removed the limit on post_max_size which was 8M and it seems to have partly fixed the issue. 编辑:我删除了post_max_size的限制,这是8M,似乎已部分解决了这个问题。 I can now upload things up to about 3MB but after that it always fails with a custom error message from the script. 我现在可以上传大约3MB的内容,但之后它总是会失败,脚本会显示自定义错误消息。

When increasing file POST limits, you may need to change at least 2 settings: 增加文件POST限制时,您可能需要更改至少2个设置:

upload_max_filesize = 30M upload_max_filesize = 30M

post_max_size = 32M post_max_size = 32M

Dont think it has anything to do with CloudFlare. 不要认为它与CloudFlare有任何关系。 See if you can check the error log for Apache if the above settings dont work. 如果以上设置不起作用,请查看是否可以检查Apache的错误日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM