Skip to content

Instantly share code, notes, and snippets.

@ramainen
Created August 13, 2014 10:54
Show Gist options
  • Save ramainen/514a76743bedbbc7bbf3 to your computer and use it in GitHub Desktop.
Save ramainen/514a76743bedbbc7bbf3 to your computer and use it in GitHub Desktop.
file download attachment
<?php
function download_file($adress){
$adress = str_replace('+',' ',$adress);
$file = d()->File->where('title = ?',$adress);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename*=UTF-8''".rawurlencode( $file->title).'.'.$file->ext."");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
//header('Pragma: public');
//header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($_SERVER['DOCUMENT_ROOT'] . $file->file);
exit();
print $file->ext;
print $file->file;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment