Sunday 15 June 2014

download - Sending File in Chunk from Server in PHP -



download - Sending File in Chunk from Server in PHP -

i developing embedded device has simple miro-controller limited memory. device request file server sending http (or https) method request server. there php script in server responsible send file. php script send file continuously embedded device. embedded device not fast plenty , not have plenty memory store whole file before processing it. want php script sending chunk of file in each http request. think size of chunk determined variable in request. , in each chunk add together header describing size, sequence number, , crc check of chunk.

i newbie on php script. help guild me write php script? illustration appreciated.

thank much.

i think script php read file , take chunk want:

$filename = "yourfile.txt"; $chunk_length = 1024; // 1024 chars sent $sequence_number = $_get['sequence']; if ($sequence_number>0){ $position = $sequence_number * $chunk_length; } else { $position = 0; } $content = file_get_contents($filename); $data = substr($content, $position, $chunk_length); header('size:'.strlen($data)); header('sequence_number:'.sequence_number); header('crc:'.crc32($data)); echo $data;

php download

No comments:

Post a Comment