我正在使用 php 中的 ZipArchive 创建 zip 文件。
$path = Yii::getPathOfAlias('webroot').'/quickshopimages/productimage/';
$zip =new ZipArchive();
$zip->open('test.zip', ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
$iterator=new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST);
foreach($iterator as $file)
{
if($file->isDir())
{
echo strtoupper($file->getRealpath()), PHP_EOL.'<br/>';$file .'/');
$zip->addEmptyDir(str_replace(strtoupper($file->getRealpath()) . '/', '',
$file . '/'));
}
else
{
$zip->addFile($file);
}
}
$zip->close();
但这里的问题是,当我创建zip时,它的文件夹结构设置为
C:''程序文件 (x86)''EasyPHP-5.3.5.0''www''quickshop''trunk''quickshopimages''productimage''male''shirts''Ethnic''1
我的主要根目录来自"productimage''male''shirts''Ethnic''1"。那么,如何从"产品图片"作为根目录启动zip文件夹?
提前感谢,对不起英语
请参阅下面的答案,您的问题似乎来自您使用$zip->addFile($file);,没有第二个参数。
PHP 创建没有 zip 内文件路径的 zip
Yii有一个zip扩展名。易拉链分机
$zip = Yii::app()->zip;
$zip->makeZip('./','./toto.zip'); // make an ZIP archive
$zip->extractZip('./toto.zip', './1/'); // extract Zip arc.