code_junkie

Securly download file inside browser with correct filename

Nov 13th, 2011
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. // check security, get filename from request, prefix document download directory and check for file existance then...
  2.  
  3. header('Content-Type: application/pdf');
  4. header('Content-Disposition: attachment; filename="' . basename($file) . '"');
  5. header('Content-Transfer-Encoding: binary');
  6. header('Content-Length: ' . filesize($file));
  7. header('Connection: Close');
  8. set_time_limit(0);
  9. readfile($file);
  10.  
  11. http___example.com_index.php_page=secure_area_download&file=protected.pdf
  12.  
  13. index.php?page=secure-area/download&file=document.pdf
  14.  
  15. file/secure-area/download/document.pdf
  16.  
  17. RewriteEngine On
  18. RewriteRule ^file/secure-area/download/(.*)$ index.php?page=secure-area/download&file=$1 [L]
  19.  
  20. // check security, get filename from request, prefix document download directory and check for file existance then...
  21. header('Content-Type: application/pdf');
  22. header('Content-Disposition: inline; filename="' . basename($file) . '"');
  23. header('Content-Transfer-Encoding: binary');
  24. header('Content-Length: ' . filesize($file));
  25. header('Connection: Close');
  26. set_time_limit(0);
  27. readfile($file);
  28.  
  29. document.pdf
  30.  
  31. http___example.com_index.php_page=secure_area_download&file=document.pdf
  32.  
  33. Content-Disposition: inline;
Add Comment
Please, Sign In to add comment