Changeset 12391

Show
Ignore:
Timestamp:
08/10/11 05:28:24 (2 years ago)
Author:
mbrevda
Message:

add download_file function that sends a file to a browser for download

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/amp_conf/htdocs/admin/libraries/utility.functions.php

    r12378 r12391  
    979979      : false; 
    980980 } 
     981 
     982/** 
     983 * downloads a file to the browser (i.e. sends the file to the browser) 
     984 *  
     985 * @author Moshe Brevda mbrevda => gmail ~ com 
     986 * @pram string 
     987 * @pram string, optional 
     988 * @pram string, optional 
     989 */ 
     990function download_file($file, $name = '', $type = '') { 
     991  if (file_exists($file)) { 
     992    $name = $name ? $name : basename($file); 
     993    $type = $type ? $type : 'application/octet-stream'; 
     994    header('Content-Description: File Transfer'); 
     995    header('Content-Type: ' . $type); 
     996    header('Content-Disposition: attachment; filename=' . $name); 
     997    header('Content-Transfer-Encoding: binary'); 
     998    header('Expires: 0'); 
     999    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
     1000    header('Pragma: public'); 
     1001    header('Content-Length: ' . filesize($file)); 
     1002    ob_clean(); 
     1003    flush(); 
     1004    readfile($file); 
     1005    exit; 
     1006  } else { 
     1007    return false; 
     1008  } 
     1009}