php:我可以压缩没有完整路径的 glob 文件吗?

发布于 2024-12-14 11:31:29 字数 385 浏览 3 评论 0原文

这段代码就像在糟糕的一天里送来一批​​神奇的新鲜薯片:纯粹的快乐。但是当我提取存档时,文件嵌套在它们存储在服务器上的路径中。我不喜欢。我如何在没有完整路径的情况下压缩 glob;只是文件。

$zip = new ZipArchive();
$zip->open("_dox/pdftmp/".$_SESSION['archiveName'], ZipArchive::CREATE);
$files_pdf = glob('_dox/pdftmp/*.pdf');
foreach ($files_pdf as $file)
{
  $zip->addFile($file);
}
$zip->close();

请记住:只有文件,没有额外的文件夹。

写!

this code works like a magic batch of fresh potato chips on a really bad day: PURE JOY. but when i extract the archive, the files are nested in the path they were stored in on the server. me no likey. how do i zip the glob without the full path; just the files.

$zip = new ZipArchive();
$zip->open("_dox/pdftmp/".$_SESSION['archiveName'], ZipArchive::CREATE);
$files_pdf = glob('_dox/pdftmp/*.pdf');
foreach ($files_pdf as $file)
{
  $zip->addFile($file);
}
$zip->close();

remember: just files, no extra folders.

WR!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动听の歌 2024-12-21 11:31:29

指定 zip 中文件的“本地名称”。请参阅 addFile() 文档。

$zip->addFile($file, basename($file));

Specify the "local name" that the files will have inside the zip. See the addFile() docs.

$zip->addFile($file, basename($file));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文