Skip to content

Instantly share code, notes, and snippets.

@npget
Last active June 6, 2018 10:57
Show Gist options
  • Save npget/7055b7d125b4d8f6b56cba31616ed8fa to your computer and use it in GitHub Desktop.
Save npget/7055b7d125b4d8f6b56cba31616ed8fa to your computer and use it in GitHub Desktop.
<?php
public function open_file_exp_doc($url){
header('Content-Description:NpGet-Archistore-Files');
header("Content-Type: ".$this->FileMtipe($url));
header("Content-Disposition: inline; filename=".basename($url));
header('Content-Transfer-Encoding: binary\n');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
ob_clean();
flush();
readfile($url);
}
public function FileMtipe($url){
$ctype=null;
$ext=pathinfo($url, PATHINFO_EXTENSION);
switch ($ext) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "xml": $ctype="text/plain"; break;
case "txt": $ctype="text/plain"; break;
case "docx":$ctype="text/plain"; break;
case "doc": $ctype="text/plain"; break;
case "csv": $ctype="text/plain"; break;
case "sds": $ctype="text/plain"; break;
case "prn": $ctype="text/plain"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":$ctype="image/jpeg"; break;
case "jpg":$ctype="image/jpeg"; break;
//default: $ctype="application/force-download";
}
return $ctype;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment