Download File Using Php

I added the code to download the file using php. When we apply this concept, dont need to give the file dirctory to user.

function downloadfile($filepath){
         // Change it based on file extension or type
         header("Pragma: public");
         header("Content-Type: $type");
         header("Cache-Control: public");
         header("Content-Description: File Transfer");
         header("Content-Disposition: attachment;filename=\"".basename($filepath));
         header('Content-Length: '.filesize($filepath));
         header("Content-Transfer-Encoding: binary");
	 header("Expires: 0");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");



This entry was posted in PHP and tagged .

Leave a Reply

Your email address will not be published. Required fields are marked *