Jump to content

Zip archive and Windows


Drongo_III
Go to solution Solved by AbraCadaver,

Recommended Posts

Hi Guys

 

This is a bit of a weird one and I wondered if perhaps someone here had experienced this and found a work around.

 

I'm using zip archive on a project at the moment. Basic version of the code is below.

 

When I zip a file and output it to the browser using headers it works fine in the example below. BUT if I try to add a file from another directory, as in the commented out line below, the resulting zipped folder can't be unzipped in windows. When I try I get a "The folder XXXX is invalid" message.

 

I sent the same zipped folder to my htc phone and it opened the zipped folder no problem.

 

The puzzling thing about windows is that it works fine if the image originates in the same directory as the executing script and can be opened no problem.

 

So is this something anyone else has encountered? And how can you get around it?

$zip = new ZipArchive();
                if ($zip->open('./test2.zip',ZipArchive::CREATE) === TRUE) {
                               
                              //$zip->addFile('../fileUploadLocation/somefolder/image1.jpeg');
                                $zip->addFile('image3.jpeg');
                                $zip->close();
                                echo 'ok';
                } else {
                                echo 'failed';
}
Link to comment
Share on other sites

  • Solution

You need to use the second parameter to give the file an alternate name or else the file will be added with the full linux path and won't unzip on windoze:

$zip->addFile('../fileUploadLocation/somefolder/image1.jpeg', 'image1.jpeg');
//or maybe this for a subdir
$zip->addFile('../fileUploadLocation/somefolder/image1.jpeg', 'somefolder/image1.jpeg');
Link to comment
Share on other sites

 

You need to use the second parameter to give the file an alternate name or else the file will be added with the full linux path and won't unzip on windoze:

$zip->addFile('../fileUploadLocation/somefolder/image1.jpeg', 'image1.jpeg');
//or maybe this for a subdir
$zip->addFile('../fileUploadLocation/somefolder/image1.jpeg', 'somefolder/image1.jpeg');

 

 

Thanks Abra!

 

I will try this tomorrow. See i knew one of clever peeps here would have it down :)

 

Drongo

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.