<?phpclass Transfer { /**
 * 下载的开始点
 *
 * @access private
 * @var integer
 */
private $mDownStart; /**
 * 文件大小
 *
 * @access private
 * @var integer
 */
private $mFileSize; /**
 * 文件句柄
 *
 * @access private
 * @var integer
 */
private $mFileHandle; /**
 * 文件全路径
 *
 * @access private
 * @var string
 */
private $mFilePath; /**
 * 文件下载时显示的文件名
 *
 * @access private
 * @var string
 */
private $mFileName; /**
 * 构造函数
 *
 * @access public
 * @return void
 **/
public function __construct() {
} /**
 * 下载
 *
 * @param string $pFilePath 文件全路径
 * @param string pFileName 文件下载时显示的文件名,缺省为实际文件名
 * @access public
 * @return void
 **/
public function Down($pFilePath, $pFileName = '') {
$this->mFilePath = $pFilePath;
if (!$this->iniFile())
$this->sendError();
$this->mFileName = empty($pFileName) ? $this->getFileName() : $pFileName; $this->iniFile();
$this->setStart();
$this->setHeader(); $this->send();

fclose($this->mFileHandle);
} /**
 * 初始化文件信息
 *
 * @access private
 * @return boolean
 **/
private function iniFile() {
if (!is_file($this->mFilePath))
return false;
$this->mFileHandle = fopen($this->mFilePath, 'rb');
$this->mFileSize = filesize($this->mFilePath);
return true;
} /**
 * 设置下载开始点
 *
 * @access private
 * @return void
 **/
private function setStart() {
if (isset($_SERVER['HTTP_RANGE'])) {
preg_match("/^bytes=([0-9]+)-$/i", $_SERVER['HTTP_RANGE'], $match);
$this->mDownStart = $match[1];
fseek($this->mFileHandle, $this->mDownStart);
} else {
$this->mDownStart = 0;
}
} /**
 * 设置http头
 *
 * @access private
 * @return void
 **/
private function setHeader() {
@header("Cache-control: public");
@header("Pragma: public");
header("Content-Length: " . ($this->mFileSize - $this->mDownStart));
if ($this->mDownStart > 0) {
@header("HTTP/1.1 206 Partial Content");
header("Content-Range: bytes " . $this->mDownStart . "-" . ($this->mFileSize - 1) . "/" . $this->mFileSize);
} else {
header("Accept-Range: bytes");
}
@header("Content-Type: application/octet-stream");
@header("Content-Disposition: attachment;filename=" . $this->mFileName);
} /**
 * 获取全路径里的文件名部分
 *
 * @access private
 * @return string
 **/
private function getFileName() {
return basename($this->mFilePath);
} /**
 * 发送数据
 *
 * @access private
 * @return void
 **/
private function send() {
// fpassthru($this->mFileHandle);

while (!feof($this->mFileHandle)) {
set_time_limit(0);
$buffer = fread($this->mFileHandle, 1024 * 1024);
echo $buffer;
flush();
ob_flush();
}
} /**
 * 发送错误
 *
 * @access public
 * @return void
 **/
public function sendError() {
@header("HTTP/1.0 404 Not Found");
@header("Status: 404 Not Found");
exit();
}
}$transfer = new Transfer;
$transfer->Down('D:\Pro lab\Aptana workspace\ezine\ezine\201202161811\VOL_001_201202161811.zip');我同时打开一个浏览器的两个标签页,然后执行以上所示的php脚本,不知道为啥,文件是不能同时下载的。
如果我直接把文件放到apache的根目录下,用同样的打开两个标签页的方式访问这个文件,文件就能被同时下载了,我想是不是php存在类似于“锁”的东西,限制了这个文件被同一个客户端同时下载?
跪求大神指点。