PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Sep 23, 2019 3:25 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 44 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Wed Jan 25, 2006 11:30 am 
Offline
Forum Regular

Joined: Sat Jul 09, 2005 10:22 am
Posts: 594
Location: Israel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 12:40 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 3:13 pm 
Offline
Spockulator
User avatar

Joined: Wed Feb 04, 2004 9:15 pm
Posts: 4714
Location: Eden, Utah
<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 :P

very nice work RM.
</yoda_off>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 6:59 pm 
Offline
Tutorials Group

Joined: Sun Jan 04, 2004 11:30 pm
Posts: 2692


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 7:35 pm 
Offline
Spockulator
User avatar

Joined: Wed Feb 04, 2004 9:15 pm
Posts: 4714
Location: Eden, Utah


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 8:15 pm 
Offline
Tutorials Group

Joined: Sun Jan 04, 2004 11:30 pm
Posts: 2692


Top
 Profile  
 
PostPosted: Sun Mar 19, 2006 8:38 pm 
Offline
Forum Newbie

Joined: Sun Mar 19, 2006 8:31 pm
Posts: 5


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 2:53 pm 
Offline
Forum Regular

Joined: Thu Dec 18, 2003 4:58 pm
Posts: 836
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...
Syntax: [ Download ] [ Hide ]
$prefix  = basename($zip_dir) . '/';

then find the following line...
Syntax: [ Download ] [ Hide ]
$ZIP->add_file($contents, $name, filemtime($name));

and replace with....
Syntax: [ Download ] [ Hide ]
$ZIP->add_file($contents, $prefix . $name, filemtime($name));


and also find the following line...
Syntax: [ Download ] [ Hide ]
$ZIP->add_file('', $name, filemtime($name));

and replace with with...
Syntax: [ Download ] [ Hide ]
$ZIP->add_file('', $prefix . $name, filemtime($name));


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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 5:45 pm 
Offline
Forum Newbie

Joined: Sun Mar 19, 2006 8:31 pm
Posts: 5
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.


Syntax: [ Download ] [ Hide ]
if (is_dir("$folderpath/$row[1]"))      

{$icon = "<img border='0' src='images/folder.ico'>&nbsp;"

              ."<a href='zipcreate.ex3.php?dvddir=$folderpath&albumname=$row[1]'>zipit</a>";}


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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 6:01 pm 
Offline
Forum Regular

Joined: Thu Dec 18, 2003 4:58 pm
Posts: 836


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 6:09 pm 
Offline
Forum Newbie

Joined: Sun Mar 19, 2006 8:31 pm
Posts: 5


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 6:32 pm 
Offline
Forum Regular

Joined: Thu Dec 18, 2003 4:58 pm
Posts: 836
I'd say most of what you need to do the job is included in the example scripts (specifically the script you are already using (ex3)), it should just be a case of breaking them down to understand what they are doing. And from there just adding a few simple rountines on top.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 8:31 am 
Offline
Forum Newbie

Joined: Sun Mar 19, 2006 8:31 pm
Posts: 5
Thanks redmonkey

added
Syntax: [ Download ] [ Hide ]
$prefix  = basename($zip_dir) . '/';


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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 10:46 am 
Offline
Forum Newbie

Joined: Sun Mar 19, 2006 8:31 pm
Posts: 5
Just trial and error but this done the trick

Changed

Syntax: [ Download ] [ Hide ]
return array($files, $directories);

To
Syntax: [ Download ] [ Hide ]
return array($files);


Any other implication or problems i might be causing by doing this?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 01, 2006 9:16 pm 
Offline
Forum Contributor

Joined: Sat Feb 08, 2003 3:36 am
Posts: 110
Location: San Jose, CA


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 44 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group