Home  >  Article  >  Backend Development  >  PHP code to implement file downloading in IE

PHP code to implement file downloading in IE

WBOY
WBOYOriginal
2016-07-25 09:03:47863browse
  1. if( empty($_GET['FileName'])|| empty($_GET['FileDir'])|| empty($_GET['FileId'])){
  2. echo' <script> alert("Illegal connection!"); location.replace ("index.php") </script>'; exit();
  3. }
  4. $file_name=$_GET['FileName'];
  5. $ file_dir=$_GET['FileDir'];
  6. $FileId=$_GET['FileId'];
  7. $file_dir = $file_dir."/";
  8. if (!file_exists($file_dir.$file_name)) { //Check Whether the file exists
  9. echo "File not found";
  10. exit;
  11. } else {
  12. $file = fopen($file_dir . $file_name,"r"); // Open the file
  13. // Enter the file label
  14. Header(" Content-type: application/octet-stream");
  15. Header("Accept-Ranges: bytes");
  16. Header("Accept-Length: ".filesize($file_dir . $file_name));
  17. Header("Content- Disposition: attachment; filename=" . $file_name);
  18. // Output file content
  19. echo fread($file,filesize($file_dir . $file_name));
  20. fclose($file);
  21. exit();
  22. }
  23. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn