SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard wide's Avatar
    Join Date
    Apr 2004
    Location
    Denmark
    Posts
    1,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Compress the content of a directory/folder

    Hi all,

    Is it possible to compress everything within a directory/folder (files, folders etc) and place the file in that specific folder (/backup.gz) with a php code?
    ...

  2. #2
    Resident Java Hater
    Join Date
    Jul 2004
    Location
    Gerodieville Central, UK
    Posts
    446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use the system / exec commands in PHP to call gzip and tar as you would from the command line and using file_exists() after to ensure the archive is created.

    You can also do it natively with ...

    http://pear.php.net/package/Archive_Tar

  3. #3
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about:
    PHP Code:
    exec("tar -cf $archivename $path");
    exec("gzip  $archivename");
    exec("mv $archivename.gz $targetdir"); 

  4. #4
    SitePoint Enthusiast mrsmiley's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a look at the streams section of the php manual. While its a little hazy on how to use it, its most certainly possible. The streams code is also very fast.

    Other than that, there are several compression extensions you can use depending on your archive flavour (bzip, tar, zip, gzip, lzw, etc). Then its just a matter of iterating through your directories, adding file to the archive, and then removing the original files once done and verified.

    Depends how native you want the solution. Using exec or system to run gzip wont help on Windows.

  5. #5
    SitePoint Wizard wide's Avatar
    Join Date
    Apr 2004
    Location
    Denmark
    Posts
    1,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, that should do
    ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •