Lets start by looking at what I am trying to accomplish.
I work for a web bureau, and we use almost the same CMS for every website. The CMS contains over 6000 files, so it takes a long time to upload. It is much faster to upload a zipped file, and then unzip it on the FTP server.
I browsed stackoverflow, and found this thread: Unzip a file with php
This is fine. However, when i use this code:
<?php
// assuming file.zip is in the same directory as the executing script.
$file = 'concrete5.6.3.1-Dansk.zip';
// get the absolute path to $file
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
// extract it to the path we determined above
$zip->extractTo($path);
$zip->close();
echo "WOOT! $file extracted to $path";
} else {
echo "Doh! I couldn't open $file";
}
?>
I get the following problem:
It unzips the entire .zip file. This is including the folder that was originally compressed. Which will create my index.php file, one directory too deep.
So instead of this: www.hello.com/index.php
It will come out as: www.hello.com/folder/index.php
That was problem #1.
Here is problem #2:
I work on mac, and when I unzip my zipped file, I get the annoying "_macosx" folder too.
Is there a way to fix both of these issues? :)