title: Uploading Images with PHP Script Failing
body: <p>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 <a href="http://thegeekoftheworld.com/using-a-php-upload-script-for-sharex/" rel="nofollow">this one</a>.</p>
  
  <p>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.</p>
  
  <p>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. After 60 seconds, I get a 502 error (Bad Gateway) on ShareX.</p>
  
  <p>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.</p>
  
  <pre><code>max_execution_time = 60
  max_input_time = 60
  memory_limit = 128M
  post_max_size = 8M
  </code></pre>
  
  <p>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. There is no middle ground, it's either it succeeds instantly or times out after 60 seconds.</p>
  
  <p>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:</p>
  
  <p>StackTrace:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Edit: My server is behind cloudflare, and I read that cloudflare might cause problems. 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.</p>
  
  <p>Edit: I removed the limit on post_max_size which was 8M and it seems to have partly fixed the issue. I can now upload things up to about 3MB but after that it always fails with a custom error message from the script.</p>