【发布时间】:2015-10-09 07:10:13
【问题描述】:
我正在使用这篇文章LAMP: How to create .Zip of large files for the user on the fly, without disk/CPU thrashing中的以下脚本
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename="file.zip"');
// use popen to execute a unix command pipeline
// and grab the stdout as a php stream
// (you can use proc_open instead if you need to
// control the input of the pipeline too)
//
$fp = popen('zip -r - tmp/01-55-34_561764e6cb06e', 'r');
// pick a bufsize that makes you happy (8192 has been suggested).
$bufsize = 8192;
$buff = '';
while( !feof($fp) ) {
$buff = fread($fp, $bufsize);
echo $buff;
}
pclose($fp);
我的文件夹中有我的文件:tmp/01-55-34_561764e6cb06e
我得到了一个可用的 zip 文件,但问题是我的 zip 文件中也包含了路径。
当我打开它时,我的 zip 文件看起来像这样
tmp/01-55-34_561764e6cb06e/image1.jpg
tmp/01-55-34_561764e6cb06e/image2.jpg
tmp/01-55-34_561764e6cb06e/image3.jpg
tmp/01-55-34_561764e6cb06e/image4.jpg
我只想拥有图像,没有文件夹 (tmp/...)。
文件结构
/var/www/html/script.php
/var/www/html/tmp/01-55-34_561764e6cb06e/image1.jpg
/var/www/html/tmp/01-55-34_561764e6cb06e/image2.jpg
/var/www/html/tmp/01-55-34_561764e6cb06e/image3.jpg
我不想让我的脚本与图片放在同一个文件夹中!
【问题讨论】: