本文介绍了下载PHP脚本服务的文件时,网站无法使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行IIS 8.0并且有一个脚本可以在有人点击下载链接时提供各种下载。然而,我遇到了一个问题,只要用户下载的东西,网站完全没有响应,直到下载完成。下面是下载脚本的代码。此脚本将在新窗口中打开。

I'm running IIS 8.0 and have a script that serves various downloads when someone clicks on a download link. However I'm running into an issue where as long as a user is downloading something the website is completely unresponsive until that download completes. Below is the code for the download script. This script is being opened in a new window.

$extension = fileexten($filename);
if(($filename!= false)&&($fakename!=false&& @fopen($filename,'r')==true)){
  $mime = contenttype($extension);
  set_time_limit(0);
  header('Pragma: public');
  header('Expires: 0'); 
  header("Content-Type:".$mime);
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Cache-Control: private', false);        
  header('Content-Disposition: attachment;filename='.$fakename.'.'.$extension);
  header("Content-Transfer-Encoding: binary");

  if (ob_get_length() > 0) {
    ob_end_clean();
  }
  flush();
  readfile($filename);
}
else{
  $error = "<h3>We could not find this file</h3>";} // If the filename or fake filename could not be retrieved. 
}


推荐答案

在输出之前关闭会话文件。

Close the session before outputting the file.

session_write_close();
readfile($filename);

会话一次只能由一个PHP进程打开,并且任何其他请求都会发出 session_start()命令将在等待访问会话数据文件时阻塞。

The session can only be opened by one PHP process at a time, and any other requests that issue a session_start() command will block while waiting for access to the session data file.

这篇关于下载PHP脚本服务的文件时,网站无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 03:19