zip文件夹,不使用getRealPath

时间:2015-01-28 10:12:13

标签: php

我正在尝试从我的localhost服务器内的文件夹中创建zip文件,这是我的计算机,带有Windows 7操作系统到主机。问题是使用getRealPath来制作zip文件,zip文件内容就像这样“ D:\ xampp \ htdocs \ mobl \ admin \ downloads“但我不希望我的zip文件中包含这些文件夹。 如何在没有这些文件夹和目标文件夹的情况下制作zip文件?

这是我用来压缩文件夹的代码

enter code here

$ zip = new ZipArchive;

$zip->open('downloads/'.$zipname,ZipArchive::CREATE);

// Initialize empty "delete list"
$filesToDelete = array();

// Create recursive directory iterator
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootPath),
    RecursiveIteratorIterator::LEAVES_ONLY);

foreach($files as $name => $file) {
    // Get real path for current file
    $filePath = $file->getRealPath();

    // Add current file to archive
    $zip->addFile($filePath);
}

// Zip archive will be created only after closing object
$zip->close();

由于

0 个答案:

没有答案