Skip to content

Instantly share code, notes, and snippets.

@zisan34
Forked from Robiussani152/delete-hidden-files.php
Created October 28, 2020 09:04
Show Gist options
  • Save zisan34/84319d7c4f2992eff52e3599dc6ac04d to your computer and use it in GitHub Desktop.
Save zisan34/84319d7c4f2992eff52e3599dc6ac04d to your computer and use it in GitHub Desktop.
Ftp related important files.
<?php
/**
* Find and delete all hidden files in $dir
* Usage: remove-hidden-files.php OR remove-hidden-files.php /path/to/parse/
*
* Without path parameter, the current path is being used.
*
* (C)ommitted 2015 by @author Fabian Wolf (@link http://usability-idealist.de/)
*
* @license GNU GPL v3
*/
// find all hidden files in $dir (eg. the current one)
$dir = './';
if( !empty($argv[1]) ) { // first parameter
if( !file_exists( $argv[1] ) ) {
echo "\n" . $argv[1] . " does not exist.\n";
exit(1);
} elseif( file_exists( $argv[1] ) && !is_dir( $argv[1] ) ) {
echo "\n" . $argv[1] . " is not a directory.\n";
exit(2);
}
$dir = '' . $argv[1];
}
$result = shell_exec( 'find ' . $dir . ' -type f -iname ".*" -print' );
if( !empty( $result ) ) {
echo "\nFound the following files in [$dir]:\n" . $result;
$hidden_files = explode("\n", trim($result) );
} else {
echo "\nFound no hidden files in [$dir].\n";
}
if( !empty( $hidden_files ) ) {
// now, lets remove em
foreach( $hidden_files as $strFileName ) {
echo "\nRemoving $strFileName ...";
if( unlink( $strFileName ) != false ) {
echo " done.\n";
} else {
echo " failed!\n";
}
}
}
<?php
function deleteAll($dir) {
foreach(glob($dir . '/*') as $file) {
if(is_dir($file))
deleteAll($file);
else
unlink($file);
}
rmdir($dir);
}
deleteAll('root');
<?php
/*
* PHP Recursive Backup-Script to ZIP-File
* (c) 2012: Marvin Menzerath. (http://menzerath.eu)
*/
// Make sure the script can handle large folders/files
ini_set('max_execution_time', 600);
ini_set('memory_limit','1024M');
// Start the backup!
zipData('./', './backup.zip');
echo 'Finished.';
// Here the magic happens :)
function zipData($source, $destination) {
if (extension_loaded('zip') === true) {
if (file_exists($source) === true) {
$zip = new ZipArchive();
if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) {
$source = realpath($source);
if (is_dir($source) === true) {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$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();
}
}
return false;
}
<?php
$zip = new ZipArchive;
$res = $zip->open('file_name.zip');
if ($res === TRUE) {
$zip->extractTo('./');
$zip->close();
echo 'Extract success!';
} else {
echo 'Extact failed!';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment