Skip to content

Instantly share code, notes, and snippets.

@Domm98CZ

Domm98CZ/index.php

Created May 22, 2021
Embed
What would you like to do?
PHP Helper files
<?php
if(!empty($_GET["t"]) && isset($_GET["t"]) && is_numeric($_GET["t"])) {
echo "<strong>Datum:</strong> <pre>".date("d. m. Y H:i:s", $_GET["t"])."</pre>";
echo "<hr>";
}
echo "<strong>Timestamp:</strong> <pre>".time()."</pre>";
echo "<hr>";
echo "<strong>_SERVER:</strong> <pre>";
print_r($_SERVER);
echo "</pre>";
?>
<?php
// Identify directories
$source = __DIR__."/DIR/abc/";
$destination = __DIR__.'/';
// Function to remove folders and files
function rrmdir($dir) {
if (is_dir($dir)) {
$files = scandir($dir);
foreach ($files as $file)
if ($file != "." && $file != "..") rrmdir("$dir/$file");
rmdir($dir);
}
else if (file_exists($dir)) unlink($dir);
}
// Function to Copy folders and files
function rcopy($src, $dst) {
if (file_exists ( $dst ))
rrmdir ( $dst );
if (is_dir ( $src )) {
mkdir ( $dst );
$files = scandir ( $src );
foreach ( $files as $file )
if ($file != "." && $file != "..")
rcopy ( "$src/$file", "$dst/$file" );
} else if (file_exists ( $src ))
copy ( $src, $dst );
}
rcopy($source, $destination);
?>
<?php
function Zip($source, $destination)
{
if (!extension_loaded('zip') || !file_exists($source)) {
return false;
}
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
return false;
}
$source = str_replace('\\', '/', realpath($source));
if (is_dir($source) === true)
{
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file)
{
$file = str_replace('\\', '/', $file);
// Ignore "." and ".." folders
if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
continue;
$file = realpath($file);
if (is_dir($file) === true)
{
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
}
else if (is_file($file) === true)
{
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
}
else if (is_file($source) === true)
{
$zip->addFromString(basename($source), file_get_contents($source));
}
return $zip->close();
}
$wannaDir = null;
if(isset($_GET['d']) && !empty($_GET['d'])) {
$wannaDir = $_GET['d'];
}
$directoryPacker = __DIR__ . '/packerArchive/';
$directory = __DIR__ . '/../';
$scanned_directory = array_diff(scandir($directory), array('..', '.'));
if($wannaDir !== null && in_array($wannaDir, $scanned_directory, true)) {
Zip($directory . $wannaDir, $directoryPacker . $wannaDir . '.zip');
}
else {
foreach($scanned_directory as $dir) {
Zip($directory . $dir, $directoryPacker . $dir . '.zip');
}
}
?>
<?php
$wannaDir = null;
if(isset($_GET['d']) && !empty($_GET['d'])) {
$wannaDir = $_GET['d'];
} else {
die();
}
$pathZip = __DIR__ . '/backups/' . $wannaDir . '.zip';
$pathExt = __DIR__ . '/domains/' . $wannaDir . '';
$zip = new ZipArchive;
$res = $zip->open($pathZip);
var_dump($res);
if ($res === TRUE) {
$zip->extractTo($pathExt);
$zip->close();
echo 'woot!';
} else {
echo 'doh!';
}
?>
<?php
$pathZip = __DIR__ . '/vendor.zip';
$pathExt = __DIR__ . '/vendor';
// Function to remove folders and files
function rrmdir($dir) {
if (is_dir($dir)) {
$files = scandir($dir);
foreach ($files as $file)
if ($file != "." && $file != "..") rrmdir("$dir/$file");
rmdir($dir);
}
else if (file_exists($dir)) unlink($dir);
}
// vendor
$zip = new ZipArchive;
$res = $zip->open($pathZip);
var_dump($res);
if ($res === TRUE) {
rrmdir($pathExt);
$zip->extractTo($pathExt);
$zip->close();
echo 'woot!';
} else {
echo 'doh!';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment