首页 新闻 会员 周边 捐助

php中zip文件损坏问题

0
悬赏园豆:40 [已关闭问题] 关闭于 2013-11-22 11:49

简单说,我的php页面在本机测试没错
放到服务器上有错。

<?php

class Sdownload
{
private $mDownStart;

private $mFileSize;

private $mFileHandle;

private $mFilePath;

private $mFileName;

/***
* @access public
* @return roid
*/
public function __construct()
{}

/*
* 下载
* $param string @pFilePath
* @param string @pFileName
* @access public
* @return void
*/
public function Down($pFilePath,$pFileName = '')
{
//echo $pFilePath;

$this->mFilePath = $pFilePath;

if(!$this->IniFile())
{
$this->SendError();
}

$this->mFileName = empty($pFileName) ? $this->GetFileName() : $pFileName;
//echo $this->mFileName;
//exit;
//$this->IniFile();

$this->SetStart();

$this->SetHeader();

$this->Send();
}

/*
* 初始化文件
*
*/
private function IniFile()
{

if(!is_file($this->mFilePath))
{
return false;
}

$this->mFileHandle = fopen($this->mFilePath, 'rb');
$this->mFileSize = filesize($this->mFilePath);

return true;
}

/*
* 设置下载开始点
*/
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头
*/
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( "Accept-Length: ".$this->mFileSize);

//header( "Content-type:application/octet-stream ");
header("Content-Type: application/octer-stream");
//header("Content-Type: application/zip");
header("Content-Disposition: attachment;filename=" .$this->mFileName);

}

/*
* 获取全路径里的文件名部分
*/
private function GetFileName()
{
return basename($this->FilePath);
}

/*
* 发送数据
*/
private function Send()
{
//readfile($this->FileHandle);
//echo $this->mFileHandle;

fpassthru($this->mFileHandle);
}

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

这是下载类

下面是下载页:

error_reporting(E_ALL | E_STRICT);
require_once(ROOT_PATH .'/framework/helper/download.class.php');
//echo '1--1=';
//echo file_exists("/home/www/test/zhangyf/newbook/". $this->filename).'1--1';
//建文件下载对象

$sd = new Sdownload();

$this->path = "/home/www/test/zhangyf/newbook/". $this->filename;
//echo $this->path;
//echo $this->filename;

$sd->Down($this->path, $this->filename);

要下载的是一个zip文件
高手都来呀。
急寻解决!

laputa~的主页 laputa~ | 初学一级 | 园豆:191
提问于:2011-12-02 11:45
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册