Re: Download files in File Galleries
PHP's readfile() function is indeed broken in some releases, which is why the download does not work for files greater than 2000000 bytes.
Fortunately there is a fairly uncomplicated hack around this (thanks to an developer at my work place who pretty much figured this out for me):
Step 1:
In tiki-download_file.php, replace the following line:
readfile($fgal_use_dir.$info%22path%22);
With a call to a new funct. which you'll add to lib/init/initlib.php (at least that's where I put it...)
your_functname($fgal_use_dir.$info%22path%22); # for example
Step 2:
Add your new, custom "readfile()" code to lib/init/initlib.php
function your_functname ($filename) {
set_time_limit(14400); // Prevent timeout - 4 hours should be enough
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt = 0;
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
$cnt += strlen($buffer);
}
$status = fclose($handle);
if ($status) {
return $cnt;
}
return false;
}