Posts

Showing posts with the label download file

How to force PDF/Image to download in PHP website?

I have used the below code in reference to php.net, Please try the below code it works. function downloadFile ( $fullPath ){   // Must be fresh start   if( headers_sent () )     die( 'Headers Sent' );   // Required for some browsers   if( ini_get ( 'zlib.output_compression' ))     ini_set ( 'zlib.output_compression' , 'Off' );   // File Exists?   if( file_exists ( $fullPath ) ){         // Parse Info / Get Extension     $fsize = filesize ( $fullPath );     $path_parts = pathinfo ( $fullPath );     $ext = strtolower ( $path_parts [ "extension" ]);         // Determine Content Type     switch ( $ext ) {       case "pdf" : $ctype = "application/pdf" ; break;       case "exe" : $ctype = "application/octet-stream" ; break;     ...