tcsnguy08 Posted January 25, 2009 Share Posted January 25, 2009 I got the whole creating a zip file and adding zip files to it using PHP. However, I can't get this code to work to extract a file from the zip file and put it in a specified folder. When I created my zip file, I put all the files into a directory Dir1, but using the code below, I can't get the any of the files in this directory to extract. I got this off of the PHP Manual zip function. I reworked it for my own use. Can someone find out why my file(s) aren't extarcting. Here is the directory structure of the zip file: MainZipFILE | | | | | | | Directory1 | | | || | | Files 1 Files 2 Files 3 I want to extract files 2 only to another folder, Folder 2 Without maintiaining the directory structure ie. I want Files 2 be saved into Folder 2 like this. Folder 2 ||||||||| Files 2 The problem I think I am having is when the zip file opens it isn't opening the Directory 1, and so it doesn't extract the files, since they are in the Directory 1 folder. here is the code I have so far: /*How would I set the archive so that it opens the Inside folder Directory 1?*/ $archive = "MainZipfile\\directory1.""; /* Shouldn't the above open up the directory inside the Mainzipfile?*/ $zip = new ZipArchive(); if ($zip->open($archive) !== true){ echo"could not open zip file"; } $zip->extractTo(Folder2, Files2); $zip->close(); Link to comment https://forums.phpfreaks.com/topic/142396-extracting-a-file-from-a-directory-in-a-zip-file/ Share on other sites More sharing options...
jscix Posted January 25, 2009 Share Posted January 25, 2009 Having no idea how the zip class your using works. I would say to simply unzip the archive to a temporary folder, then manually move the files afterward. Link to comment https://forums.phpfreaks.com/topic/142396-extracting-a-file-from-a-directory-in-a-zip-file/#findComment-746084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.