Jump to content

Extracting a file from a directory in a zip file


tcsnguy08

Recommended Posts

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(); 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.