Page 1 of 1

simple dowloader script in php ??

Posted: Mon May 28, 2007 10:59 pm
by PHPycho
Hello forums!!
I havent use the php downloader script(ie using headers).
Can anybody suggest me how to write downloading script in php?
Thanks in advance to all of you

Posted: Mon May 28, 2007 11:29 pm
by feyd
We've had a lot of threads covering this subject. Please search for "force download" and/or read the manual on header().

Posted: Wed May 30, 2007 12:27 am
by PHPycho
I found this one,
I dont know how effective is this?
any comments on this code:

Code: Select all

<?php
    
    function getmimetype ($filename) {
        static $mimes = array(
            '\.jpg$|\.jpeg$'  => 'image/jpeg',
            '\.gif$'          => 'image/gif',
            '\.png$'          => 'image/png',
            '\.html$|\.html$' => 'text/html',
            '\.txt$|\.asc$'   => 'text/plain',
            '\.xml$|\.xsl$'   => 'application/xml',
            '\.pdf$'          => 'application/pdf'
        );
    
        foreach ($mimes as $regex => $mime) {
            if (eregi($regex, $filename)) return $mime;
        }
        return 'text/plain';
    }
    $file = $_GET["file"];
    header('Pragma: public');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Content-Type: ' . getmimetype($file));
    header('Content-Disposition: attachment; filename=' . basename($file) . ';');
    header('Content-Length: ' . filesize($file));
 
    readfile($file);
?>