Loading...
 
Features / Usability

Features / Usability


Download files in File Galleries

posts: 4

I have files in files in a file gallery and I can not download the ones over 2 megs. It will bring up the download box and it will just pause at 1.7-1.9 megs. If I go directly to the file (not useing tiki's file download) it works fine. Why is this and where can I change it to download bigger files?

Thanks

posts: 2881 United Kingdom

See RecipeBigUploads

Damian

posts: 4

I can upload big files just fine it is the downloading of the files that I am having problems with. I am not sure if it because I am useing php 5.0.4 or not but I did not see any thing in PHP.ini that would be preventing me from downloading big files.

> See RecipeBigUploads
>
> Damian

posts: 4

I figured out that is issue is with PHP version 5.0.4(the one available on SunFreeWare.com) and the readfile() command. This command does not work correctly in this PHP version so don't use it with tikiwiki.

> I can upload big files just fine it is the downloading of the files that I am having problems with. I am not sure if it because I am useing php 5.0.4 or not but I did not see any thing in PHP.ini that would be preventing me from downloading big files.
>
> > See RecipeBigUploads
> >
> > Damian


posts: 28

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;
}