Using the PHP Zip library
function UnzipFile($file_path, $extract_path)
{
$zip = new ZipArchive;
$res = $zip->open($file_path);
if ($res === true) {
$zip->extractTo($extract_path);
$zip->close();
return true;
} else {
return false;
}
}
UnzipFile(
'c:/caminho/completo/do/arquivo.zip',
'c:/caminho/completo/do/diretorio/onde/quer/extrair/'
);
With something simple like this could solve.
It would be enough to have a zip file containing all the files and folders in the administrative panel system.
When a customer signs up, unzip the file to that client's folder. After that, of course, I assume that you need to change some files to customize the installation for the client.
At this point you can use a fopen()
, file_put_contents()
or other more friendly means with interface for a lay user to make the initial arrows.
Using exec ()
Alternatively, you can choose to command line.
exec('unzip c:/caminho/completo/do/arquivo.zip c:/caminho/completo/do/diretorio/onde/quer/extrair/');
In Linux environment normally unzip is available.
For Windows environment you can use some specific program like 7zip, winrar, or even the JAVA jar.
The command line is still much faster because it uses the features of the Operating System.
obs: The method of copying the files recursively is much more time-consuming and there is still a risk of something going uncopied. But it does not mean that it is wrong and that failure will always occur.