Code:
<?php
/*
* CodeIgniter 3.0 autoinstaller
*
* By Anderson Salas (http://github.com/andersonsalas)
****************************************************************************************/
set_time_limit(0);
$file_source = 'https://github.com/bcit-ci/CodeIgniter/archive/3.0.0.zip';
$file_target = 'ci_dist.zip';
$ci_dist_folder_name = 'CodeIgniter-3.0.0';
function post_install(){
/*
* Post installation function, optional:
*/
echo '<script>window.location = "index.php"</script>';
}
/****************************************************************************************/
$rh = fopen($file_source, 'rb');
$wh = fopen($file_target, 'w+b');
if (!$rh || !$wh) {
die('Unknow error');
}
while (!feof($rh)) {
if (fwrite($wh, fread($rh, 4096)) === FALSE) {
return false;
}
echo ' ';
flush();
}
fclose($rh);
fclose($wh);
function cpy($source, $dest){
if(is_dir($source)) {
$dir_handle=opendir($source);
while($file=readdir($dir_handle)){
if($file!="." && $file!=".."){
if(is_dir($source.DIRECTORY_SEPARATOR.$file)){
if(!is_dir($dest.DIRECTORY_SEPARATOR.$file)){
mkdir($dest.DIRECTORY_SEPARATOR.$file);
}
cpy($source.DIRECTORY_SEPARATOR.$file, $dest.DIRECTORY_SEPARATOR.$file);
} else {
copy($source.DIRECTORY_SEPARATOR.$file, $dest.DIRECTORY_SEPARATOR.$file);
}
}
}
closedir($dir_handle);
} else {
copy($source, $dest);
}
}
function rrmdir($dir){
if(is_dir($dir)){
$objects = scandir($dir);
foreach ($objects as $object) {
if($object != "." && $object != ".."){
if(filetype($dir.DIRECTORY_SEPARATOR.$object) == "dir") rrmdir($dir.DIRECTORY_SEPARATOR.$object); else unlink($dir.DIRECTORY_SEPARATOR.$object);
}
}
reset($objects);
rmdir($dir);
}
}
if(!class_exists('ZipArchive')) {
die('ZipArchive class not found.');
}
$zip = new ZipArchive;
if ($zip->open(__dir__.DIRECTORY_SEPARATOR.$file_target) === TRUE) {
if(is_writeable(__dir__.DIRECTORY_SEPARATOR)) {
$zip->extractTo(__dir__);
$zip->close();
cpy(__DIR__.DIRECTORY_SEPARATOR.$ci_dist_folder_name,__DIR__);
rrmdir(__dir__.DIRECTORY_SEPARATOR.$ci_dist_folder_name);
$borrar = array($ci_dist_folder_name,basename(__file__),$file_target);
foreach($borrar as $archivo){
if(file_exists(__dir__.DIRECTORY_SEPARATOR.$archivo)){
unlink(__dir__.DIRECTORY_SEPARATOR.$archivo);
}
}
mkdir(__DIR__.DIRECTORY_SEPARATOR.'assets');
fopen(__DIR__.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'index.html', 'w');
mkdir(__DIR__.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'css');
fopen(__DIR__.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.'index.html', 'w');
mkdir(__DIR__.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'js');
fopen(__DIR__.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'index.html', 'w');
mkdir(__DIR__.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'img');
fopen(__DIR__.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'index.html', 'w');
mkdir(__DIR__.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'fonts');
fopen(__DIR__.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'fonts'.DIRECTORY_SEPARATOR.'index.html', 'w');
mkdir(__DIR__.DIRECTORY_SEPARATOR.'incoming');
fopen(__DIR__.DIRECTORY_SEPARATOR.'incoming'.DIRECTORY_SEPARATOR.'index.html', 'w');
fopen(__DIR__.DIRECTORY_SEPARATOR.'.htaccess','w');
$file = __DIR__.DIRECTORY_SEPARATOR.'.htaccess';
$current = file_get_contents($file);
$current .= '<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /'.basename(__dir__).'/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond $1 ^$
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>';
file_put_contents($file, $current);
post_install();
die;
} else {
die('Can\'t write the target dir');
}
} else {
die('Can\'t read the downloaded zip');
}