Snippets v2

Languages
My Snippets

Readfile over internet connection Login or Register to Bookmark this snippet

Description PHP

Reads the content of a file, either local or remote (http://blah) in chunks that are protocol safe and avoid network disruption.

The Code Download
  1. <?php
  2. function readfile_chunked ($filename) {
  3.     $chunksize = 1*(1024*1024); // how many bytes per chunk
  4.     $buffer = '';
  5.     $contents = '';
  6.     $handle = fopen($filename, 'rb');
  7.     if ($handle === false) {
  8.         return false;
  9.     }
  10.     while (!feof($handle)) {
  11.         $buffer = fread($handle, $chunksize);
  12.         $contents .= $buffer;
  13.     }
  14.     fclose($handle);
  15.     return $contents;
  16. }
  17. ?>
Credits Contact JC

Added by JC on 12th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment