General Question

lefteh's avatar

Anybody know how I can integrate .zip files with PHP?

Asked by lefteh (9414points) June 8th, 2008

Instead of asking an explicit question, I’ll give you my goal and ask you to help me get there:
I’d like my site administrator to be able to upload a .zip file full of images, which would then be expanded into an image directory on the website.

Observing members: 0 Composing members: 0

10 Answers

jrpowell's avatar

http://www.net2ftp.com/ allows you to do this. You could dig through the source (you can download it there) and figure out how they did it. Or you could just install net2ftp and have them use that instead.

Skyrail's avatar

http://uk2.php.net/manual/en/book.zip.php give that page a try, some useful zip functions. I’m quite tired now and I’m not a PHP guru but if you enlighten me more on the situation I can gather more info :) (tomorrow of course)

Vincentt's avatar

See http://nl.php.net/zip/

The PHP Manual/Reference is excellent :)

(And I see there are more decompression extensions – Bzip2, interesting, thanks for asking this question :)

lefteh's avatar

Thanks for the responses.
Using some of the resources I found, I am at this point:

// These are libraries lifted from phpMyAdmin
require_once(“zip.lib.php”);
require_once(“unzip.lib.php”);

$zip = new SimpleUnzip();
$filename = “myzippedfile.zip”;
$entries = $zip->ReadFile($filename);

foreach ($entries as $entry) {
$fh = fopen($entry->Name, ‘w’, false);
fwrite($fh,$entry->Data);
fclose($fh);
}

This DOES unzip the data, however the files are currently corrupted.
I think it has something to do with my working on a local web server set up on my Mac, with those nasty ._ resource files.
We’ll see where I can go from here….

GeauxTigers's avatar

Sorry to be a smart-ass, but come on. Google it

lefteh's avatar

Of course I Googled it.
If you’d take the time to look at your search results, you’d notice that the pages are almost entirely dedicated to either getting around extracting zip files or other people asking, to no avail, how they could go about doing it.
The ones that aren’t are web applications that could do it for you, which is not what I’m looking for.
Furthermore, the solution to this dilemma is going to be useful to a lot of the PHP programmers on Fluther and it’s an interesting topic for discussion.

Vincentt's avatar

@lefteh – hold on, I’ll finish checking my email, reading my feeds and the updates on Fluther, and then I’ll see if I can make a decompression application myself.

Vincentt's avatar

Well, that was easy :)

I used the native PHP zip utilities and my code worked fine. I don’t know which PHP version you have and whether Zip is enabled, but it was enabled on a default PHP 5 installation on Xubuntu.

lefteh's avatar

Yeah, I took a look at those native utilities, and they looked really useful.
The problem I ran into is that the client I’m working for is hosting on GoDaddy, which didn’t have the ZIP utilities enabled. The closest I’ve gotten is the phpMyAdmin utilities.. but those files are still corrupted.
It’s nice to have found those native utilities though, for future reference. They’re pretty useful!

Vincentt's avatar

Well, I just downloaded PclZip and that worked fine too with my code.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther