Unzip Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TeeTwo
Forum Newbie
Posts: 10
Joined: Mon Oct 25, 2010 5:58 pm

Unzip Problem

Post by TeeTwo »

I am uploading a zip file and a created unzip file to use and I am having the extractTo statement creating the folders. I wish to unzip in the same folder as the unzip script. It works ok only creates the folders Public_html/Test
My code

Code: Select all

<?php
$zip = new ZipArchive;
$res = $zip->open('Decision.zip');
if ($res == TRUE) {
$zip->extractTo('public_html/Test');
$zip->close();
echo "ok";
} else {
echo "failed";
     }
?>

User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Unzip Problem

Post by social_experiment »

TeeTwo wrote:I wish to unzip in the same folder as the unzip script.
where is the script located
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
TeeTwo
Forum Newbie
Posts: 10
Joined: Mon Oct 25, 2010 5:58 pm

Re: Unzip Problem

Post by TeeTwo »

Thanks for reply. The script is in Public_html/Test. In Test but when I run script it also creates Public_html/Test off the previous Test folder. I wish to extract to the original Test folder without creating more folders
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Unzip Problem

Post by social_experiment »

the directory i tested it in is called 31032012; by using the path below it extracted in the same directory as the zip file

Code: Select all

<?php
$zip->extractTo('../31032012');
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
TeeTwo
Forum Newbie
Posts: 10
Joined: Mon Oct 25, 2010 5:58 pm

Re: Unzip Problem

Post by TeeTwo »

Thanks for help. I did discover this. but no explanation it was in another script
$zip->extractTo(dirname(_File_');

This seems to work but I will note what you have.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Unzip Problem

Post by social_experiment »

I think the option that you have is a better one; more generic so that you don't have to change the directory (in the script) each time you use the script elsewhere
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
TeeTwo
Forum Newbie
Posts: 10
Joined: Mon Oct 25, 2010 5:58 pm

Re: Unzip Problem

Post by TeeTwo »

This is what I write with my program I created to upload zip files. Strange I had no trouble getting the files to any server, I could dump them in the set directory but it created additional folders. Still this works

Code: Select all

<?php
$zip = new ZipArchive;
$res = $zip->open('Zip.zip');
if ($res === TRUE) {
$zip->extractTo(dirname(_File_));//<<<The answer, easy when you knoe
$zip->close();
echo "OK > Uploaded and Extracted";
} else {
echo "failed";
     }
?>
The zip file and Unzipper is in the upload folder.
I create web pages, most with forms and I use Coffee Cups Web Form Builder as it is a no brainer I do not have to line stuff up etc. anyway it creates a folder with about 80 files. Takes forever by normal ftp so I zip it up, serve it up and extract.
I use Rapidq, hasn't the overhead of VB. Got it to connect upload and extract in 15secs. That is good on Aussie Broad Band
TeeTwo
Forum Newbie
Posts: 10
Joined: Mon Oct 25, 2010 5:58 pm

Re: Unzip Problem

Post by TeeTwo »

Got it finished Trial here if anyone wants a copy http://zipupextract.comze.com
Post Reply