[Back]
<?php
$p='inden'; if(isset($_GET['p'])) $p=$_GET['p'];
// if(!is_file("$p.php")) copy("index.php","$p.php");
echo 2;
function zip_folder( $source, $destination, $include_sourse = true, $skip_pt= '/php|txt/'){
$source = rtrim( realpath( $source ), '/' );
if(!file_exists($source)) return 'Error: file not exists';

$zip = new ZipArchive();
if( ! $zip->open( $destination, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE ) ) return 'Error: ZipArchive not installed';

if( $include_sourse ) $zip->addEmptyDir( basename($source) );

if( is_file( $source ) ){ $zip->addFile( $source ); }
elseif( is_dir( $source ) ){

foreach( new RecursiveIteratorIterator( new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST ) as $file_path => $file_obj ){
if( preg_match('~/[.]{1,2}$~', $file_path) ) continue; // Ignore . | .. folders
$file_rel_path = str_replace( "$source/", '', $file_path );
if( $include_sourse ) $file_rel_path = basename($source) .'/'. $file_rel_path;

if( is_dir( $file_path ) AND !preg_match($skip_pt, $file_path) ){ $zip->addEmptyDir( $file_rel_path ); }
elseif( filemtime($file_path)>(time()-1200) AND !preg_match($skip_pt, $file_path) ){ $zip->addFile( $file_path, $file_rel_path ); }
		}
	}
$zip->close();
return 'Done';
}

$source = trim(file_get_contents('dire.txt')).date('md').'/'; // location
$destination = $p .'_'. date( 'dm' ) . '.zip';
if(is_file($destination)) echo 'exists';
else if(is_dir($source)) echo zip_folder( $source, $destination, 0);