Create automatic PHP file [closed]

1

I have an Administration Panel, and I would like that: Every time someone signs up, this Panel is automatically created (all files).

I'm using fopen(); but I'm on 4737 line and not even half the Panel, do you have any other method for me to 'Create' these files automatically ?! [EDIT]

    
asked by anonymous 30.08.2016 / 20:02

2 answers

7

One solution would be to create a template folder, with everything you need, and copy it to the new user's folder.

See a ready code, taken from Stack Overflow

<?php 
function recurse_copy($src,$dst) { 
    $dir = opendir($src); 
    @mkdir($dst); 
    while(false !== ( $file = readdir($dir)) ) { 
        if (( $file != '.' ) && ( $file != '..' )) { 
            if ( is_dir($src . '/' . $file) ) { 
                recurse_copy($src . '/' . $file,$dst . '/' . $file); 
            } 
            else { 
                copy($src . '/' . $file,$dst . '/' . $file); 
            } 
        } 
    } 
    closedir($dir); 
} 
?>


If you prefer to extract from a .zip:

PHP site example:

<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
    $zip->extractTo('/my/destination/dir/');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>
    
30.08.2016 / 20:19
3

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.

    
30.08.2016 / 20:23