PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Jul 20, 2018 3:54 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
Sorry to bump an old thread back, but I need a gzip/bz2 class that could EXTRACT tar files. Do you know where can I get one? I searched on hotscripts but most of the scripts there seem to be properiarity licsenced...


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
Just use the command line


tar -xf file.tar, creates the directory ./file/


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: 4713
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
Burrito wrote:
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

And now you know why the rest of us do that. :)


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: 4713
Location: Eden, Utah
Roja wrote:
And now you know why the rest of us do that. :)

:?:


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
Burrito wrote:
Roja wrote:
And now you know why the rest of us do that. :)

:?:

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.

Does that explain my comment better?


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

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


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
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.

Well, there are three potential problems you might encounter here....

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.


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
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.

Quote:
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.


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
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


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 3 guests


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