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 so simple I could solve.
Just have a zip file containing all the files and folders of the administrative panel system.
When a client signs up, unzip the file to the folder and drop the client. After that, logically, I require you to change some files to customize the installation for the client.
Then at that point you can use a fopen()
, file_put_contents()
or other more user friendly means with interface for a lay user can fzer the initial setagens.
Using exec()
Alternatively, you can choose the command line.
exec('unzip c:/caminho/completo/do/arquivo.zip c:/caminho/completo/do/diretorio/onde/quer/extrair/');
In Linux environment usually unzip is available.
For Windows environment you can use some specific program like 7zip, Winrar, or even JAVA jar.
The command line is even faster because it uses the resources of the Operating System.
Obs: The method of copying the files recursively is much more time consuming and you still run the risk of something going without copying. But it doesn’t mean it’s wrong and it’s always going to fail.
Fundamental reading: [Ask]. Remember that you know what you want to do, but we only have those 2 paragraphs up there that don’t give the slightest idea of the context. Try to read the link indicated, and then [Edit] the question explaining better what you really need (which files are these, because there are many, which 4737 lines are these, do what exactly, etc.). We are here to help, but for that we need to understand what the situation is.
– Bacco
:) Thanks for the indication friend! I made an Dit if you do not understand yet let me know, I think it was clear now.. I just did not understand the negative vote. This disproportions the question and left in an objective way I want to create files automatically without using the metedo of fopen
– user50712
I’d say he took a step, but we still don’t know what the breeding criteria are. If you want to apply a site "template" to a new client, it would just copy an entire folder with the templates, without any fopen. Create a "/modelo_site/" directory with all the files, and when creating the new user copy all the content to "/past_do_user/" and manage with fopen() only the configuration files, which have passwords etc.
– Bacco
It could have a single archive (.zip) with all the essential files of this "admin panel", so just extract everything with each new registration.
– Daniel Omine
I thought about this possibility @Danielomine , but I could do it automatically? Ex extract the . zip automatically ?
– user50712
Yes... PHP zip functions http://php.net/manual/en/book.zip.php
– Daniel Omine
@Bacco , I understood the concept I’m new in programming , as I would copy all these files ?! has no password as the own panel comes with the login screen
– user50712
has a code ready here that creates directories and copies all files http://stackoverflow.com/a/2050909/916193
– Bacco