1

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?

Thanks for your help

DaveRandom
  • 87,921
  • 11
  • 154
  • 174
Sjoerd
  • 45
  • 1
  • 4

2 Answers2

1

What zip program are you using? tar works in the way that you want it to above, then you can gzip it.

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.

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.

DaveRandom
  • 87,921
  • 11
  • 154
  • 174
0

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. There is an example of how at this question.

As to getting zip to work with exec, I noticed two points:

  1. you will definitely need the $filename_no_ext variable in there. 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. I don't think you want that.
  2. You do not need the trailing * to get the command line zip function to work.
Community
  • 1
  • 1
cwallenpoole
  • 79,954
  • 26
  • 128
  • 166