Internet Advertising - Equity Release - Mortgages - Loans - Per Insurance

PDA

View Full Version : Unzipping files with PHP


Nick_Mayhem
Mar 13th 2006, 7:20 am
Well as usual I am again stuck with a single line of code in my development.

I have setup a script which downloads the file automatically every 24hours.

The file is in zip format. So I want to have a peice of code that can unzip that file and extract its content on my webserver.

I tried zip_open(); but it is not working on my server as they don't have that library installed.

Any other ideas would be very helpful.

Thanks.

T0PS3O
Mar 13th 2006, 7:24 am
From PHP.net:

http://uk2.php.net/zip


f you just want to unzip a zip folder an alternative to some of the lengthy functions below is:

<?

function unzip($zip_file, $src_dir, $extract_dir)
{
copy($src_dir . "/" . $zip_file, $extract_dir . "/" . $zip_file);
chdir($extract_dir);
shell_exec("unzip $zip_file");
}

?>

You don't need the ZIP extension for this.

Nick_Mayhem
Mar 13th 2006, 7:34 am
humm... I tried both of this.

The first one gives me zip_open function. Which my server doesn't supports and I am on a shared server.

The other one is fine but then It is not giving proper results.

It is creating an empty zip file in the place of the original instaed of extracting it.

So still in the problem.

T0PS3O
Mar 13th 2006, 7:35 am
Scroll down on that page for other alternatives.

Nick_Mayhem
Mar 13th 2006, 7:58 am
K. Thanks.

Yeah I found some alternatives.