PHP Get Character Frequency
Cache Slow Pages for Performance
Youtube subscription Checker
Resizing images in PHP
Zip a File with PHP
Getting next auto_increment value from Mysql
Install PHP, MySQL, Apache the Bullet Proof Way
Benchmark your PHP with 3 lines of code
See all 8 posts
Php Tutorials RSS
video tutorials (123)
funny pictures (41)
amazing videos (27)
hilarious videos (26)
amazing pictures (21)
php tutorials (8)
computer tricks (7)
personal updates (6)
cat videos (5)
youtube tips (3)
fake news (2)
Best of Internet
Streaming Anime Episodes
Free Video Tutorials
Best of Youtube
MP3s From Google
Free Online Education
Funny Pictures Blog
Video Game Sheet Music
Free Movies Online
|Zip a File with PHP Posted on Thursday, February 14 2008|
My blog doesn't rely on MySQL to output each post, instead i generate my pages on my home comp and upload them to the server. It would be a big hassle to FTP 20 files one by one, so instead I zip all the files automatically first, before uploading to my server.
PHP has some zip functionality if you enable the zlib library in your PHP ini. I don't really like to include too many random libraries for tasks that php itself shouldn't be handling.
Instead I call 7-zip through the command line. In linux you can use p7zip. It comes with documentation over all the command line options.
It simplifies things to make bash or batch file first. The basic command line Structure for 7zip is as follows.
7z.exe [what action to take] [additional options] [filenames]
Simple ExamplesOn Windows: foo.bat
"C:\Program Files\7-Zip\7z.exe" a -tzip "C:\blah.zip" "file1" "file2" "dir\*.*"
On Linux: foo.sh
"/path/to/7z.exe" a -tzip "/home/blah/blah.zip" "/file1" "/file2" "/dir/*.*"
Then call your batch or shell file in php. Technically you could skip the batch/shell thing but why be messy.
7zip Command Line options7z.exe [command] [switches] [arguments]
- a Add
- b Benchmark
- d Delete
- e Extract
- l List
- t Test
- u Update
- x eXtract with full paths
- -- Stop switches parsing
- -ai Include archive filenames
- -an Disable parsing of archive_name
- -ao Overwrite mode
- -ax Exclude archive filenames
- -i Include filenames
- -m Set Compression Method
- -o Set Output directory
- -p Set Password
- -r Recurse subdirectories
- -scs Set charset for list files
- -seml Send archive by email
- -slp Set Large Pages mode
- -slt Show technical information
- -sfx Create SFX archive
- -si Read data from StdIn
- -so Write data to StdOut
- -ssc Set Sensitive Case mode
- -ssw Compress files open for writing
- -t Type of archive
- -u Update options
- -v Create Volumes
- -w Set Working directory
- -x Exclude filenames
- -y Assume Yes on all queries
- Wild Cards
- '*' means a sequence of arbitrary characters.
- '?' means any character.
- Wildcard Examples
- *.txt means all files with an extension of ".txt"
- ?a* means all files with a second character of "a"
- *1* means all names that contains character "1"
- *.*.* means all names that contain two "." means characters
- Exit Codes
- 0 No error
- 1 Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed.
- 2 Fatal error
- 7 Command line error
- 8 Not enough memory for operation
- 255 User stopped the process
You can also use winrar and unrar the files. It also works in linux. There's always gzip too. It's just a matter of getting the command line options down. 7zip was way more processor intensive when extracting a massive 7zip archive. Winrar is much kinder if you're going to be handling bigger files. 7zip has a much higher compression quality if you archive into their .7z format
Tags: 7zip cli, command line arguements, arguments, tar, untar, deflate, gzip, unrar linux
More OMFG-Good LinksSee all Posts in the Funny Pictures category.
Download mp3s faster than limewire using google.
I've made 100+ free video tutorials.
See the best of the internet today on one page.