[100分]DZ7.0论坛附件下附大大问题,要怎么设置单线程

janly 2009-01-12 11:52:50
attachment.php
在这个文件中有4种模式下载
每一种都不完善,下载一定时间后断线,
谁能帮我修改为单线条下载并且不断线.
...全文
189 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
海诗美妆 2009-01-13
  • 打赏
  • 举报
回复
断线的主要原因应该是网络或者是服务器处理能力问题。
只能是推荐用flashget,支持断点连接。
syu 2009-01-13
  • 打赏
  • 举报
回复
改大脚本执行时间.
用重定向,而不是由PHP读-输出附件
ai_ni 2009-01-13
  • 打赏
  • 举报
回复
不懂,帮顶.
janly 2009-01-13
  • 打赏
  • 举报
回复
刚去网上找的,是单线程下载,唯2点不好的,
一是用IE打开无法提示下载,而是直接打开,
二是用迅雷下载可下载,但总大小无法显法,

小弟我从来不懂PHP,谁能帮我修改上面2个小问题,然后再通过这段代码,想办法放入BBS里去



<?php
/**
* 支持断点续传下载
* 实例代码:
* $down = new SD_DownLoad();
* $down->Down('E:/iso/MS.Office2003SP1.CHS.iso');
**/
class SD_DownLoad {

/**
* 下载的开始点
*
* @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();
}


/**
* 初始化文件信息
*
* @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 (!empty($_SERVER['HTTP_RANGE']) && preg_match("/^bytes=([\d]?)-([\d]?)$/i", $_SERVER['HTTP_RANGE'], $match)) {
if(empty($match[1])) $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-Ranges: bytes" . $this->mDownStart . "-" . ($this->mFileSize - 1) . "/" . $this->mFileSize);
}
else {
Header("Accept-Ranges: 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);
}

/**
* 发送错误
*
* @access public
* @return void
**/
public function SendError() {
@header("HTTP/1.0 404 Not Found");
@header("Status: 404 Not Found");
exit();
}
}
?>


<?
$down = new SD_DownLoad();
$down->Down('H:/圆通的人际关系.zip');

?>

Zijian_Zhang 2009-01-13
  • 打赏
  • 举报
回复
这是最简单的,否则是要一定工程量的。
Zijian_Zhang 2009-01-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 janly 的帖子:]
attachment.php
在这个文件中有4种模式下载
每一种都不完善,下载一定时间后断线,
谁能帮我修改为单线条下载并且不断线.
[/Quote]客户端解决,用迅雷、FlashGET那些东西,支持断点续存功能。
janly 2009-01-13
  • 打赏
  • 举报
回复
请问在哪里修改脚本执行时间, 是IIS执行超时吗?现在是120秒,用IE下载可以达到10分钟左右就断了。
用迅雷下载长一点的时间

我是用FTP做文件服务器的,速度我可以限制,不能重定向,这样直实地址人家会知道并且知附件名称全是英文!
要怎么实现单线程下载,急急,高手帮忙
yctin 2009-01-13
  • 打赏
  • 举报
回复
那个主要是在服务器设定的
PHP效果不大~难实现
songzairan 2009-01-13
  • 打赏
  • 举报
回复
帮顶

4,250

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧