简体   繁体   English

exec zip根路径

[英]exec zip root path

Im having some problems zipping a directory. 我在压缩目录时遇到一些问题。 The following line will do the trick but it also includes the root directory. 以下行将完成此操作,但它还包括根目录。

exec('zip -r '.$tmp_zip.' '.$filename_no_ext.'/rss-ticker/*'); 

So I only want to zip everything in the dir rss-ticker How to fix this? 所以我只想将所有内容压缩在rss-ticker目录中。如何解决此问题?

Thanks for your help 谢谢你的帮助

What zip program are you using? 您正在使用什么压缩程序? tar works in the way that you want it to above, then you can gzip it. tar工作中,你希望它上面的方式,那么你可以gzip它。

Alternatively, chdir() to the directory you want to zip, and specify your path as * - that should only get the files in the current working directory. 或者,将chdir()压缩到要压缩的目录,然后将路径指定为* -仅应将文件保存在当前工作目录中。

If you can't get it to work in the way you want to (or even if you can) try the ZIP Extension or this 3rd party library - doing it in pure PHP will make your code more portable. 如果您无法按照您想要的方式(甚至可以)使用它,请尝试使用ZIP扩展程序第3方库 -使用纯PHP进行操作将使您的代码更具可移植性。

Unless you have an overwhelming reason not to (like a desire to cause yourself much pain and headache), you really should be using the ZipArchive toolkit. 除非您有一个压倒性的理由(例如希望自己造成很多痛苦和头痛),否则您确实应该使用ZipArchive工具箱。 There is an example of how at this question . 这个问题有一个例子。

As to getting zip to work with exec , I noticed two points: 关于使用zip与exec配合工作,我注意到两点:

  1. you will definitely need the $filename_no_ext variable in there. 您肯定在那里需要$filename_no_ext变量。 If you just have it be a . 如果你拥有它的话. . Right now, because you're starting rss-ticker with / , it is assuming that the folder is at the root of the file-system. 现在,由于您要使用/来启动rss-ticker ,因此假设该文件夹位于文件系统的根目录下。 I don't think you want that. 我不想要你
  2. You do not need the trailing * to get the command line zip function to work. 您不需要结尾的*来使命令行zip函数起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM