note 88549 modified in function.readfile by danbrown
| From: | danbrown@php.net | Date: | Thu, 29 Jan 2009 00:55:27 +0000 |
| Subject: | note 88549 modified in function.readfile by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149920@lists.php.net to get a copy of this message | ||
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;
}
?>
--was--
Here is my version of readfile_chunked
you can make it act like file() or file_get_contents()
by using the type arg
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;
}
enjoy!
http://php.net/manual/en/function.readfile.php