note 88549 deleted from function.readfile by joey
| From: | joey@php.net | Date: | Mon, 21 Jan 2013 10:01:42 +0000 |
| Subject: | note 88549 deleted from function.readfile by joey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193291@lists.php.net to get a copy of this message | ||
Note Submitter: rmatakajr at gmail dot com
----
Here is my version of readfile_chunked
you can make it act like file() or file_get_contents()
by using the type arg
<?php
function readfile_chunked ($filename,$type='array') {
$chunk_array=array();
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
switch($type)
{
case'array':
// Returns Lines Array like file()
$lines[] = fgets($handle, $chunksize);
break;
case'string':
// Returns Lines String like file_get_contents()
$lines = fread($handle, $chunksize);
break;
}
}
fclose($handle);
return $lines;
}
?>