I had an issue where some files were being downloading as zero byte files from FileLister snippet. After some investigation i found the php memory limit was being exceeded by files of size ~30Mb, even though php memory_limit was 128Mb. I found the solution was to update my FileLister snippet like so:
find:
$o = file_get_contents($curPath);
echo $o;
change to:
// If it's a large file we don't want the script to timeout, so:
set_time_limit(300);
// If it's a large file, readfile might not be able to do it in one go, so:
$realpath = $modx->config['base_path'].$curPath;
$chunksize = 1 * (1024 * 1024); // how many bytes per chunk
$size = intval(sprintf("%u", filesize($realpath)));
if ($size > $chunksize) {
$handle = fopen($realpath, 'rb');
$buffer = '';
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
}
fclose($handle);
} else {
readfile($realpath);
}
I've put a request in to have this added to FileLister, but cross posted here in case it can help anyone out in the meantime.
The php manual page (and comments) are a good resource for troubleshooting issues with file download:
http://www.php.net/manual/en/function.readfile.php#99406
[ed. note: christianhanvey last edited this post 15 years, 1 month ago.]