hello,
i m beginner in php,

and i want to download a file,

here is my code

ob_start();

// location with filename
$filename = "downloads/code.zip";

if(file_exists($filename))
    {
                    header("Content-Disposition : attachment; filename=" . urlencode($filename));
                    header("Content-Type : application/force-download");
                    header("Content-Type : application/octet-stream");
                    header("Content-Type : application/download");
                    //header("Content-Type : application/zip");
                    header("Content-Description : File Transfer");
                    header("Content-Length : " . filesize($filename));
                    flush();

                    //readfile($filename);

                    $fp = fopen($filename, "r");
                    $content = '';
                    while(!feof($fp))
                    {
                        $content .= fread($fp, 65536);
                        flush(); // It is essential for large file download.
                    }
                     fclose($fp);
    }
    else
    {
        echo 'File not exist!';
    }
    

ob_end_flush();

but from this i m not able to download anything :(

please help for this

You can't/shouldn't send 3 content-type headers. That doesn't make sense because the file only has one content type. That might be messing things up. Only send the octet-stream header.

Rather than doing the fopen()...fclose(), just use your readfile() code - much simpler. The one thing to check though, is whether the path to the file is correct. You can run file_exists() on the path & see if PHP knows about the file.

hello quasipickle,
thanks for you suggestion but the problem is solved now

header("Content-Type : application/download");

this is the correct way

header("Content-Type: application/download");

i gave the space between Content-Type and :

Sounds like you found the solution. Please flag this as "solved".