Page 1 of 1

Pause with download [RESOLVED]

Posted: Fri Jan 06, 2006 3:21 pm
by Technocrat
With the help of a few posts around here I figured out how to send a download to a user. The problem is there is a delay of around 30 seconds between when someone clicks and when the download start. :(

Its not the server because the download starts right away if I send the file link via header. So I am not sure what the problem is. :?

Any help would be great, thanks.

Code: Select all

if (!function_exists('mime_content_type')) {
               function mime_content_type($f) {
                   $f = escapeshellarg($f);
                   return trim( `file -bi $f` );
               }
            }
            $file = $folder . '/' . $file_name;
            $size = filesize($file);
            $content = mime_content_type($file);
            $name = basename($file);

            header("Pragma: no-cache");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: private");
            header("Content-length: $size");
            header("Content-type: $content");
            header("Content-Disposition: attachment; filename=$name");
            readfile($file);

Posted: Fri Jan 06, 2006 3:40 pm
by timvw
probably the function mime_content_type does not exists, and forking a process for "file -bi $file" might take a while... It is the reason why people moved from cgi-bin to apache modules...

possible solution: recompile php --with-mime-thingies...

Posted: Fri Jan 06, 2006 3:46 pm
by Jenk
from the comments on php.net:
sunfra at firenze dot net
29-Apr-2005 11:31
if you arern't allowed to use mime_content_type, you can use this function

Code: Select all

<?php
function mime_content_type_($filename)
{
   $mime = array(
       '.3dmf' => 'x-world/x-3dmf',
       '.a' => 'application/octet-stream',
       '.aab' => 'application/x-authorware-bin',

//[... i have to cut, the text is too long :/ ..]

       '.xwd' => 'image/x-xwd',
       '.xyz' => 'chemical/x-pdb',
       '.z' => 'application/x-compressed',
       '.zip' => 'application/x-zip-compressed',
       '.zoo' => 'application/octet-stream',
       '.zsh' => 'text/x-script.zsh',
   );
   return $mime[strrchr($filename, '.')];
}
?>

Posted: Fri Jan 06, 2006 4:40 pm
by Technocrat
timvw - That would make sense but I dont think my host is going to allow me to do this, much less can I ask users to do this. ;)

Jenk - I saw that too, but its chopped off. I am going to have to find a whole copy of it some where.

Posted: Fri Jan 06, 2006 4:47 pm
by Technocrat

Posted: Fri Jan 06, 2006 4:57 pm
by Technocrat
Still doing it though a BIT faster

I have narrowed it down to:
header("Content-length: $size");

Posted: Fri Jan 06, 2006 5:21 pm
by LiveFree
w00t its Technocrat

Posted: Fri Jan 06, 2006 5:24 pm
by Technocrat
shh :lol:

Posted: Fri Jan 06, 2006 6:02 pm
by Technocrat
GZip and the Content-length: dont like each other so to fix it I had to do:

Code: Select all

while (ob_end_clean());
	header('Content-Encoding: none');