daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $files = glob('path/to/temp/*'); // get all file names
  2. foreach($files as $file){ // iterate files
  3.   if(is_file($file))
  4.     unlink($file); // delete file
  5. }
  6.    
  7. $files = glob('path/to/temp/{,.}*', GLOB_BRACE);
  8.    
  9. foreach (new DirectoryIterator('/path/to/directory') as $fileInfo)
  10.     if(!$fileInfo->isDot())
  11.         unlink($fileInfo->getFilename();
  12.    
  13. <?php
  14.  
  15. if ($handle = opendir('/path/to/files'))
  16. {
  17.     echo "Directory handle: $handlen";
  18.     echo "Files:n";
  19.  
  20.     while (false !== ($file = readdir($handle)))
  21.     {
  22.         if( is_file($file) )
  23.         {
  24.             unlink($file);
  25.         }
  26.     }
  27.  
  28.     closedir($handle);
  29. }
  30. ?>
  31.    
  32. $dir = 'your/directory/';
  33. foreach(glob($dir.'*.*') as $v){
  34.     unlink($v);
  35. }
  36.    
  37. /**
  38.      * Delete a file or recursively delete a directory
  39.      *
  40.      * @param string $str Path to file or directory
  41.      */
  42.     function recursiveDelete($str){
  43.         if(is_file($str)){
  44.             return @unlink($str);
  45.         }
  46.         elseif(is_dir($str)){
  47.             $scan = glob(rtrim($str,'/').'/*');
  48.             foreach($scan as $index=>$path){
  49.                 recursiveDelete($path);
  50.             }
  51.             return @rmdir($str);
  52.         }
  53.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top