amazon s3 - PHP streaming upload without using /tmp


Keywords:php 


Question: 

We have a website that allows large video uploads, these are stored in Amazon S3.

There is an Ajax file uploader that uses PUT to send the file (with an upload progress bar) to a receiving PHP script that uses php://input to read the input stream and then write this data to S3.

We're using $stream = fopen("php://input", "rb") and fread($stream, 8192) to read 8KB blocks, once a few MB of data have been read this is written to S3. Each time a block of data is sent to S3 we record this in a database logging table so we know that S3 is being written to as soon as the upload process begins.

The problem is the stream is also being saved to /tmp which is filling up the available disk space on the server. Is there a simple way to prevent the file from being stored in /tmp or clearing it out after each fread()?

We can create a larger temporary area just for this uploader but there must be a more elegant solution.


1 Answer: 

I'm having the same issue, and I'm doing some research on using websockets and webworkers to solve the problem.

websocket server in PHP:

large file upload using a webworker:

I'll keep you updated!