Download Files in PHP

 |  |  | No Comments

To downloads files in the php you need to use below code. just replace your file name with  akashwagh.pdf file

<?php
$filename = 'akashwagh.pdf';

$ctype="application/[extension]";

// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');

header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");

// change, added quotes to allow spaces in filenames

header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));

readfile("$filename");

exit();
 
?>

Related Posts

Author: Akash Wagh

Hello friends, I have created akashwagh.com for the unique bloggers and readers. We’re accepting unique guest posts from real authors. If any blogger or author interested to post a blog on akashwagh.com then they are always welcome.

Leave a Reply