Guest User

Untitled

a guest
Nov 16th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <?php
  2. function ftransfer($downloadpath) {
  3. if (file_exists($downloadpath)) {
  4. set_time_limit(0);
  5. ini_set("memory_limit","512M");
  6. ini_set("max_input_time","20000");
  7. ini_set("max_execution_time","20000");
  8. $path_parts = pathinfo($downloadpath);
  9. $filename=$path_parts['basename'];
  10. header("Content-type: ".getmtype($downloadpath));
  11. header("Content-disposition: attachment; filename={$filename}");
  12. echo file_get_contents($downloadpath);
  13. exit;
  14. }
  15. else { die('Error: No such file ('.$downloadpath.')'); }
  16. exit;
  17. }
  18. function getmtype($file_path) {
  19. $mtype = '';
  20. if (function_exists('finfo_file')) {
  21. $finfo = finfo_open(FILEINFO_MIME); // return mime type
  22. $mtype = finfo_file($finfo, $file_path);
  23. finfo_close($finfo);
  24. }
  25. else if (function_exists('mime_content_type')) {
  26. $mtype = mime_content_type($file_path);
  27. }
  28. if ($mtype == '') {
  29. $mtype = "application/force-download";
  30. }
  31. return $mtype;
  32. }
Add Comment
Please, Sign In to add comment