Uploading multiple file upload using PUT request
<p>I am trying to upload files in CHUNKS using PUT request using Jquery to PHP server.
I have created code where I am able to Upload the chunk file.
But something weird is happenening when I try to read it using "php://input"</p>

<pre><code>&lt;?php
  $headerArray=getallheaders();
  $filename="d/".$headerArray["filename"];
  $length=$headerArray["Content-Length"];
  /* PUT data comes in on the stdin stream */
  echo "filename".$filename;
  echo "Chunksize Uploaded:".$length;

  $putdata = fopen("php://input", "r");

  /* Open a file for writing */
  $fp = fopen($filename, "a");

  while ($data = fread($putdata, $length))
    fwrite($fp, $data);

  /* Close the streams */
  fclose($fp);
  fclose($putdata);

  echo "FileSize After write : ".filesize($filename);
?&gt;
</code></pre>

<p>Here I am able to successfully upload the file in chunks when I am sending each chunk one by one and waiting for code to write that chunk to file.</p>

<p>But when I do the concurrent uploads(Do not wait for the first chunk to be written in the file ) .. data in the "php://input" seems got overwritten by the next request.</p>

<p>I have doble checked the javascript. So the problem is at php end "how should i read the CHUNKS?".</p>

<p>I have gone through the follwing link and several other links:
<a href="http://php.net/manual/en/features.file-upload.put-method.php" rel="nofollow">http://php.net/manual/en/features.file-upload.put-method.php</a></p>

<p>Can somebody help me to understand how php://input works when it recives multiple request at the same time .. does data gets overwritten or the data gets QUEUED in STDIN?</p>
