How to compress a directory in PHP?

Discussion in 'PHP' started by HNH992, Jul 2, 2010.

  1. #1
    Hi
    I have a directory in my website and it has directories, sub-directories and files.
    I want to compress them in a zip file.

    For example, I have this folder (named Backup) in my website:
    http://mysite.com/backup
    Code (markup):
    It has 2 folders and a file:
    test1
    test2
    file.php

    I want to compress "Backup" folder in a zip file.

    and the zip file will be like this:
    test1
    test2
    file.php

    I tried some zip classes but it makes the zip file like this:
    Backup -->
    ||||||||||test1
    ||||||||||test2
    ||||||||||file.php

    I don't want to add "Backup" folder in the zip file, I only want to add its contents.

    Do you have a good zip class doing what I want?

    Thanks
     
    Last edited: Jul 2, 2010
    HNH992, Jul 2, 2010 IP
  2. c_programmer

    c_programmer Peon

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you tell us the libraries that you have not had success with? I've used PHP's standard zip functions with success before.

    Also, do you have access to your server? If you do it would be better to have a server program do this opposed to a high level scripting language.
     
    c_programmer, Jul 2, 2010 IP
  3. HNH992

    HNH992 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    I tried PCLZIP.
    It works great but there is the problem that I explained above.

    I tried PHP functions:
    http://www.php.net/manual/en/book.zip.php
    Code (markup):
    But they didn't work.

    I'm trying to zip files on AppServ but later I will upload it to vps.
     
    HNH992, Jul 2, 2010 IP
  4. c_programmer

    c_programmer Peon

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Dont use PHP for this if you have a VPS. Find a computer based zipping program and work with that, it will work faster and more reliably. I recommend the command line version of 7-zip.
     
    c_programmer, Jul 2, 2010 IP
  5. HNH992

    HNH992 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    The problem is the vps is not for me, it's for my friend. I used some of its space to make something.
    Anyway, I solved the problem.

    Thanks
     
    HNH992, Jul 2, 2010 IP