I am completely confused on how to go about this....

I am fully aware of the fact that the 'zip' extension is read-only, but I need to create the archive with PHP. I cannot ask the user to upload a .zip file because I cannot control what the user puts in it. Sure, I can verify what kind of files are in the .zip archive, and delete the file if it does not match requirements, but that would be a lot harder to do, and the script would have more security flaws. I have checked out the PEAR Archive_Zip library but it has not yet been released. How would I go about creating a .zip file with PHP, if possible?

    PEAR library is the best way to go

      Originally posted by drag0n
      PEAR library is the best way to go

      Ah, but since that particular library has not yet been released, I guess I have to wait for it to come out; they haven't even released a beta yet! Is there any other library that can use? If so, what is it? Thanks for the help so far.

        Yay! I found a library called PclZip. All I can say is that it's a good thing I know French. 😃

        However, I won't have the opportunity to test out this library for another few days. In the meantime, if you know of any good external zip libaries, please post them here; the thread will remain unresolved until I test out the extenstion. Thanks for the help.

        [edit]Sorry for pointing you guys to the NAC Orchestra website[/edit]

          Ya know Merve, there's a lot of command line utilites that will zip files for you. I know most Linux systems have multiple utilies built in (Bzip2, GZip, Zip, Compress), where as on Windows, there's a lot available for download (I think Winzip even has a command line interface). So with the proper tool installed on the system, a simple exec() or system(), etc call would create the archive for you....

          [edit]Just to add some useful links. I'm guessing this is Windows? The first one is the Winzip addon or command line access. Beyond that are a couple free utilities that work at the command line.

          http://download.com.com/3000-2250-9479561.html?tag=lst-0-8
          http://download.com.com/3000-2250-10179817.html?tag=lst-0-6
          http://download.com.com/3000-2250-10229169.html?tag=lst-0-2

          And I deal in the RAR format a lot, so with Windows, I typically use WinRAR, which also supports command line actions.

          HTH

            Wouldn't WinZip have to be on the server for that? I want people to be able to use the script I'm making with the least fuss...I guess I should tell what i'm using this for. I'm trying to make a contest site using PHP...I was inspired after people said that a coding contest website would be nice. I started with making a coding contest website, and realised that it would be nice to have a reusable script. I guess I could bundle the library with the package.....

              Well, what kind of interaction with the zip functionality will the user need to have? I was under the impression that they would upload the files to the server, and then the server would zip them up....

                ko - i was messing around with zips a few weeks ago myself.i figured it all out pretty well - EXCEPT how to ADD files to an existing zip archive. ive also tried some open source scripts - but no luck... id be happy about any ideas.

                  What program are you using for zips sid?

                  I haven't done much playing around with these before, but it seems to be fairly uncharted territory....I'll have to start playing...

                    ill post it tomorrow - i'm ot on my main machine and cant think of the names right now - though the one mentioned earlier (PclZip) was one of them if i recall that correctly (i know one of them was french)

                      Well, I've played around with a couple of them....
                      WinZip's annoying. The non-licensed version makes you manually close the command window, saying "Buy our product to not have to do this".

                      WinRAR's my fav. It's got massive amounts of options on the command line. So many that I only got through some of the basics before moving on, but again, it's also not free.

                      Of the couple free ones, they're all pretty basic as far as command line goes. -a for add, -r for recursive, -d for delete, and so on. So, I'm wondering, which one does everyone think would be best? I'm thinking that whichever one is the better, I'll start trying to get some easy-to-implement functions done, and maybe put those up in the code crituqe forum for people to rip apart. So....what do you guys think?

                        4 days later

                        Maybe I'm wrong to assume this, but most people can open .zip files, right? I want to go with the kind of archive anybody can open.

                          Originally posted by LordShryku
                          Well, what kind of interaction with the zip functionality will the user need to have? I was under the impression that they would upload the files to the server, and then the server would zip them up....

                          Yes, that's exactly what I wanted to do, and I realise that my above question was quite stupid...😃 I still haven't got around to trying PclZip...in a few days...as I said, good thing I know French...

                            PHPMyAdmin has a class for creating zip files that is pretty easy to use. Download the source and the class is in its own file. Its a LOT easier than trying to figure out some other classes or writing your own. I figured the class out in <30 minutes. 🙂

                              7 days later

                              PclZip is the class I will use...once I've tested I will resolve this thread.

                                shell_exec('cd  /home/vhost/site1.com/html/ 
                                tar cf -directory | gzip -9 > directory.tar.gz
                                mv directory.tar.gz /home/vhost/site2.com/html/directory.tar.gz');

                                ok it's not a zip, creating one of those on the fly is a job beyond me but i get an acceptable result with the above.

                                i wanted zips but was happy to settle for this. i just use it to bundle up content from one site on our server to another which makes it easy for clients to download stuff.

                                  The real trick is making it cross-OS compatible. Never tried doing this with a compression other than tar. Though, I'm sure small gunzip executables exist also.

                                    well if it's a *nix server it'll probably have zip/unzip installed, right? just run a pass through that, i was playing with it earlier, it'd not hard to use. "zip -r [archive] [directory]/" will do a recursive save, just remember not to add the .zip bit to [archive] (odd i know)

                                    as for windows, who cares? 😃 but really there aren't too many hosts running windows that'll want a PHP script from what i've seen... but then PHP's supposed to be ahead of CF on windows servers, so what do i know?

                                    hth
                                    moon

                                      Even better, provide the GNU WIN32 port of whatever compression you want to use with the script. Cross compatible with the same code 🙂

                                        That's all very well and good but I'm using Windows...(slap me)

                                        It should be cross-OS compatible, and will be...well...at least for Windows and Linux.