2013-08-13

I have a file upload form on my website and when the user uploads its file to my server, I want to transport this uploaded file from my server to the cloud server. File can be large, so I decided to send the file to the cloud with 100KB portions.

Here is my PHP code sample which tries to send the file from my server to the cloud:

That code practically works, except one thing - each portion overwrites previous content.
On the first loop's iteration 100KB file is created on the cloud, on the second iteration these 100KB are replaced with another 100KB. On the last iteration approximately 28KB are uploading, so finally I have 28KB file on the cloud's server instead of whole file. What am I doing wrong? I want these parts to follow each other, not to replace.

Here are server responses if that would help:

HTTP/1.1 201 Created Date: Tue, 13 Aug 2013 15:11:09 GMT Connection:
close Server: Selectel_Storage/1.0 last-modified: Tue, 13 Aug 2013
15:11:09 GMT content-length: 0 etag: ea64231f21c952cdb57a5d3109415d09
content-type: text/html; charset=UTF-8

HTTP/1.1 201 Created Date: Tue, 13 Aug 2013 15:11:10 GMT Connection:
close Server: Selectel_Storage/1.0 last-modified: Tue, 13 Aug 2013
15:11:09 GMT content-length: 0 etag: 01ab42f6ad58b401284540d6631dae9d
content-type: text/html; charset=UTF-8

HTTP/1.1 201 Created Date: Tue, 13 Aug 2013 15:11:10 GMT Connection:
close Server: Selectel_Storage/1.0 last-modified: Tue, 13 Aug 2013
15:11:10 GMT content-length: 0 etag: 99bd6f0d3cefd75abc140b9359464d6d
content-type: text/html; charset=UTF-8

HTTP/1.1 201 Created Date: Tue, 13 Aug 2013 15:11:10 GMT Connection:
close Server: Selectel_Storage/1.0 last-modified: Tue, 13 Aug 2013
15:11:10 GMT content-length: 0 etag: 07cf64ef10e96710b8cb48022ee5dd16
content-type: text/html; charset=UTF-8

................................

HTTP/1.1 201 Created Date: Tue, 13 Aug 2013 15:11:33 GMT Connection:
close Server: Selectel_Storage/1.0 last-modified: Tue, 13 Aug 2013
15:11:33 GMT content-length: 0 etag: f01e66c96b21665bbbd19ee5e283a4e1
content-type: text/html; charset=UTF-8

Thanks in advance!

Show more