Zip class
Moderator: General Moderators
<yoda_off>
Let me start by saying I almost NEVER, EVER, EVER use other people's code, primarily because it doesn't do exactly what I want and secondarily because I like to learn why it's doing by making it myself.
However, I just used this zip class and it's flawless, so much so that I don't want to bother learning how / why it works. I think I'll keep it in my back pocket and pretend it's a built in PHP function
very nice work RM.
</yoda_off>
Let me start by saying I almost NEVER, EVER, EVER use other people's code, primarily because it doesn't do exactly what I want and secondarily because I like to learn why it's doing by making it myself.
However, I just used this zip class and it's flawless, so much so that I don't want to bother learning how / why it works. I think I'll keep it in my back pocket and pretend it's a built in PHP function
very nice work RM.
</yoda_off>
I was referring to why the rest of us *do* use packaged, proven solutions, instead of developing our own. You mentioned that you didn't do so, because you wanted to learn. But in this case, the packaged version was nearly perfect for your needs - which is a reason many others *do* use packaged solutions.Burrito wrote:Roja wrote:And now you know why the rest of us do that.
Does that explain my comment better?
How to add current foldername to path
I must agree this is an awsome script that works with no alterations needed to run.
I would ask however if anyone can explain a little thing.
Using the example "zipcreate.ex3.php" works like a charm except I would like the zip path to include the name of the actual folder being zipped.
it's easier this way cos I can select multiple zip files when I want to unzip them and they'll go back as they were originally
in case this is a little confusing:-
e.g.
folder1\subfolder\file.jpg
will only unzip to
subfolder\file.jpg
I would like it to unzip back yo
folder1\subfolder\file.jpg
Cheers all
I would ask however if anyone can explain a little thing.
Using the example "zipcreate.ex3.php" works like a charm except I would like the zip path to include the name of the actual folder being zipped.
it's easier this way cos I can select multiple zip files when I want to unzip them and they'll go back as they were originally
in case this is a little confusing:-
e.g.
folder1\subfolder\file.jpg
will only unzip to
subfolder\file.jpg
I would like it to unzip back yo
folder1\subfolder\file.jpg
Cheers all
Two options....
Either create another directory and copy or move folder1 and it's contents into the new directory and then use the third example to to zip the contents of your newly created directory.
Or add a 'prefix' variable and prepend that to $name when adding to the zip file. i.e. ...
after defining $zip_dir within the script add the following...
then find the following line...
and replace with....
and also find the following line...
and replace with with...
Untested but should do what you want.
For what it's worth, I'm currently contemplating extending the class to add easy access to this and similar type functions.
If you are dynamically creating the entire directory contents, I'd go with the first option. If however the majority of your directory structure is static than I'd be more inclined to go for the second option.
Either create another directory and copy or move folder1 and it's contents into the new directory and then use the third example to to zip the contents of your newly created directory.
Or add a 'prefix' variable and prepend that to $name when adding to the zip file. i.e. ...
after defining $zip_dir within the script add the following...
Code: Select all
$prefix = basename($zip_dir) . '/';Code: Select all
$ZIP->add_file($contents, $name, filemtime($name));Code: Select all
$ZIP->add_file($contents, $prefix . $name, filemtime($name));Code: Select all
$ZIP->add_file('', $name, filemtime($name));Code: Select all
$ZIP->add_file('', $prefix . $name, filemtime($name));For what it's worth, I'm currently contemplating extending the class to add easy access to this and similar type functions.
If you are dynamically creating the entire directory contents, I'd go with the first option. If however the majority of your directory structure is static than I'd be more inclined to go for the second option.
Thanks I'll give it a go.
My file structure is static and the path and foldernames are generated from MySQL
e.g
After a query to get what I want from my album database I link to your page like so.
I then use the values to fullfil your $zip_dir and $zipname
The reason I am going to such lengths is that I have over 5,000 albums neatly tagged and sorted into folders with the album name. I want to zip them into individual zip's named after the album (Folder their in)
Rather than right click and add to <foldername>.zip individually taking a LONG time I'd try to use this code to automate it a little. Well it's good practice for a php noobie anyways.
P.S. is there anything to stop the page timing out, it seems that if it takes too long to carry out the zip process the zip sometimes isn't created. After the statusbar loads 50 - 75 percent it jumps to the end.
My file structure is static and the path and foldernames are generated from MySQL
e.g
After a query to get what I want from my album database I link to your page like so.
Code: Select all
if (is_dir("$folderpath/$row[1]"))
{$icon = "<img border='0' src='images/folder.ico'> "
."<a href='zipcreate.ex3.php?dvddir=$folderpath&albumname=$row[1]'>zipit</a>";}The reason I am going to such lengths is that I have over 5,000 albums neatly tagged and sorted into folders with the album name. I want to zip them into individual zip's named after the album (Folder their in)
Rather than right click and add to <foldername>.zip individually taking a LONG time I'd try to use this code to automate it a little. Well it's good practice for a php noobie anyways.
P.S. is there anything to stop the page timing out, it seems that if it takes too long to carry out the zip process the zip sometimes isn't created. After the statusbar loads 50 - 75 percent it jumps to the end.
Well, there are three potential problems you might encounter here....Hwange wrote:P.S. is there anything to stop the page timing out, it seems that if it takes too long to carry out the zip process the zip sometimes isn't created. After the statusbar loads 50 - 75 percent it jumps to the end.
PHP may be timing out, you can get round that with set_time_limit()
Your webserver may be timing out, you need to look at your webservers config to adjust that.
PHP may be running out of memory.
By the sounds of it you are running this on your local machine? in which case, I'd be more inclined to script up something to run from the command line.
Yes it's on a local server using apache.
Again like I said it's good practice to learn how PHP works.
Not clever enough to run up a script but if you can point me in any direction to find out some info I'd be greatful.
I emailed winzip yesterday asking if there is a way to select multiple folders, right click, and zip to individual zips with their foldernames rather than the only current option of zipping them all to the master folder but they just said.
Again like I said it's good practice to learn how PHP works.
Not clever enough to run up a script but if you can point me in any direction to find out some info I'd be greatful.
I emailed winzip yesterday asking if there is a way to select multiple folders, right click, and zip to individual zips with their foldernames rather than the only current option of zipping them all to the master folder but they just said.
Thank you for contacting us.
We at WinZip Computing occasionally receive this request. However, to
date we have not received enough user requests to warrant adding this to
the program. I will forward your vote for this feature to development.
Thanks redmonkey
added
Then changed the 3 lines of code and it worked straight away.
Only one problem, I have folders inside too e.g.
CD1\<tracks>
CD2\<tracks>
They were also zipped perfectly but for some reason when i tested the
"Right click > extract here"
it created duplicate empty folders CD1 and CD2 alongside the main album folder.
any ideas
Thanks again for all your time and support
P.S (Added Later)
If I open this zip with winzip the extra CD1 and CD2 folders only show up when viewed "Explorer style" but if I try to delete the folder from inside winzip it says it can't find it.
Thought it might help, if you are going to add further functions to this script in the future.
added
Code: Select all
$prefix = basename($zip_dir) . '/';Only one problem, I have folders inside too e.g.
CD1\<tracks>
CD2\<tracks>
They were also zipped perfectly but for some reason when i tested the
"Right click > extract here"
it created duplicate empty folders CD1 and CD2 alongside the main album folder.
any ideas
Thanks again for all your time and support
P.S (Added Later)
If I open this zip with winzip the extra CD1 and CD2 folders only show up when viewed "Explorer style" but if I try to delete the folder from inside winzip it says it can't find it.
Thought it might help, if you are going to add further functions to this script in the future.
Just trial and error but this done the trick
Changed
To
Any other implication or problems i might be causing by doing this?
Changed
Code: Select all
return array($files, $directories);Code: Select all
return array($files);-
Sinemacula
- Forum Contributor
- Posts: 110
- Joined: Sat Feb 08, 2003 2:36 am
- Location: San Jose, CA
Glad I was pointed to your script -- even I was able to get it to work right away, zipping up a directory outside of the webspace with just minimal changes to zipcreate.ex3.php
I do have a couple of questions:
1. Is it possible to add the date to the $zipname? I've tried a couple of different things, but it doesn't seem to like having another variable in the definition of $zipname.
2. I'd like to go from zipping the directory to downloading the zipped file -- basically wanting to incorporate the end of zipcreate.ex2.php with zipcreate.ex3.php - but I haven't been able to figure out which variables I should use in place of $zipfile (which I assume I should do, since in ex2 it's defined by the building of the zip file, which is already done).
Any suggestions you could offer would be appreciated.
Thanks,
Scott
I do have a couple of questions:
1. Is it possible to add the date to the $zipname? I've tried a couple of different things, but it doesn't seem to like having another variable in the definition of $zipname.
2. I'd like to go from zipping the directory to downloading the zipped file -- basically wanting to incorporate the end of zipcreate.ex2.php with zipcreate.ex3.php - but I haven't been able to figure out which variables I should use in place of $zipfile (which I assume I should do, since in ex2 it's defined by the building of the zip file, which is already done).
Any suggestions you could offer would be appreciated.
Thanks,
Scott