我正在尝试将Zip文件下载到“计算机”中的下载文件夹中。但是它总是下载到项目的公用文件夹中。可能是什么问题? 这是我的代码:
public function Zip($source, $destination)
{
if (!extension_loaded('zip') || !file_exists($source)) {
return false;
}
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
return false;
}
$source = str_replace('\\', '/', realpath($source));
if (is_dir($source) === true) {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = str_replace('\\', '/', $file);
// Ignore "." and ".." folders
if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) {
continue;
}
$file = realpath($file);
if (is_dir($file) === true) {
//$zip->addEmptyDir($file);
} elseif (is_file($file) === true) {
$nfile = explode('project_files', $file);
$zip->addFromString($nfile[1], file_get_contents($file));
}
}
} elseif (is_file($source) === true) {
$zip->addFromString(basename($source), file_get_contents($source));
}
return $zip->close();
}