Drongo_III Posted July 24, 2013 Share Posted July 24, 2013 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'; } Quote Link to comment Share on other sites More sharing options...
Solution AbraCadaver Posted July 24, 2013 Solution Share Posted July 24, 2013 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'); Quote Link to comment Share on other sites More sharing options...
Drongo_III Posted July 24, 2013 Author Share Posted July 24, 2013 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.