步骤是这样的:
1. 用PHP调用System命令:system("tar -zcf $zipFile $tempPath", $retval);
2. 通过header方式将文件提供下载:
set_time_limit(0);
header("Content-Encoding: none");
header("Content-type: application/x-gzip");
header("Cache-Control: private");
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($zipFile));
header("Content-Disposition: attachment; filename=".basename($zipFile));
header('Pragma: no-cache');
header('Expires: 0');
readfile($zipFile);
问题: 下载完后打不开文件,Window,Linux下测试均不行。测试时,如果用zip命令打包,则可以下载后可以正确打开,或者提供输出的文件,即指定$zipFile=非tar.gz格式的文件也能正确下载并打开。请问问题是出在哪呢?
1. 用PHP调用System命令:system("tar -zcf $zipFile $tempPath", $retval);
2. 通过header方式将文件提供下载:
set_time_limit(0);
header("Content-Encoding: none");
header("Content-type: application/x-gzip");
header("Cache-Control: private");
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($zipFile));
header("Content-Disposition: attachment; filename=".basename($zipFile));
header('Pragma: no-cache');
header('Expires: 0');
readfile($zipFile);
问题: 下载完后打不开文件,Window,Linux下测试均不行。测试时,如果用zip命令打包,则可以下载后可以正确打开,或者提供输出的文件,即指定$zipFile=非tar.gz格式的文件也能正确下载并打开。请问问题是出在哪呢?
解决方案 »
- 初学,有没有什么好一点的书籍推荐?谢谢!!^_^
- PHP读取MYSQL中的中文字符乱码,请大虾帮忙
- php里面有没有函数可以操作linux里的账号
- php 关于文件下载问题 服务器上的软件通过下载文件下载下来的全是0KB
- mysql的问题
- 100分求助——关于用php生成有固定行和列的excel文件
- 我本机是Apache的Web服务器,为什么我用localhost/test.php与我用IP192.168.0.2/test.php访问,速度差那么大?
- 文本输出问题,每一行文字都是顶头的,没有空格
- 我想把这段asp代码改成PHP的,但是不知道怎么写了
- apache http能够访问,https就是404
- PHP网站调用数据库函数修改
- 如何用PHP查找字符串是否有某中文字符
tar.gz文件的MIME类型应该是 application/x-compressed-tar
即 header("Content-type: application/x-compressed-tar“);