Guest User

download remote file

a guest
Nov 23rd, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. <?php
  2. if(isset($_GET['download'])){
  3.  
  4. $size=get_size($url);
  5. $mime = "image\/png"; //for PNG Images
  6. $name = "phones.png";
  7. $url = "http://notifisolutions.com/img/backup/phones.png";
  8.  
  9. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
  10. {
  11. header('Content-Type: "' . $mime . '"');
  12. header('Content-Disposition: attachment; filename="' . $name . '"');
  13. header('Expires: 0');
  14. header('Content-Length: '.$size);
  15. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  16. header("Content-Transfer-Encoding: binary");
  17. header('Pragma: public');
  18. }
  19. else
  20. {
  21. header('Content-Type: "' . $mime . '"');
  22. header('Content-Disposition: attachment; filename="' . $name . '"');
  23. header("Content-Transfer-Encoding: binary");
  24. header('Expires: 0');
  25. header('Content-Length: '.$size);
  26. header('Pragma: no-cache');
  27. }
  28.  
  29. readfile($url);
  30. }
  31.  
  32. function get_size($url) {
  33. $my_ch = curl_init();
  34. curl_setopt($my_ch, CURLOPT_URL,$url);
  35. curl_setopt($my_ch, CURLOPT_HEADER, true);
  36. curl_setopt($my_ch, CURLOPT_NOBODY, true);
  37. curl_setopt($my_ch, CURLOPT_RETURNTRANSFER, true);
  38. curl_setopt($my_ch, CURLOPT_TIMEOUT, 10);
  39. $r = curl_exec($my_ch);
  40. foreach(explode("\n", $r) as $header) {
  41. if(strpos($header, 'Content-Length:') === 0) {
  42. return trim(substr($header,16));
  43. }
  44. }
  45. return '';
  46. }
  47. ?>
  48. <html>
  49. <head><title>Sample Download</title>
  50. </head>
  51. <body>
  52. <h1>Hellcoderz!!</h1>
  53. <p>This will download file from my other server at <a href="http://notifisolutions.com">notifisolutions.com</a>.<br>
  54. The file link is <a href="http://notifisolutions.com/img/backup/phones.png">phones.png</a></p>
  55. <p><a href="?download">Download</a></p>
  56. </body>
  57. </html>
Add Comment
Please, Sign In to add comment