コード例 #1
0
ファイル: FileManagement.php プロジェクト: juniortux/jaws
 /**
  * Removes a file or a complete directory.
  *
  * THANKS TO: http://aidan.dotgeek.org/lib/?file=function.rmdirr.php
  * @access  public
  * @param   string  $dirname File/Directory to remove
  * @return  bool    True or false on error
  */
 function FullRemoval($dirname)
 {
     // Sanity check
     if (!file_exists($dirname)) {
         return false;
     }
     // Simple delete for a file
     if (is_file($dirname)) {
         return @unlink($dirname);
     }
     // Loop through the folder
     $dir = @dir($dirname);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         // Recurse
         Jaws_FileManagement::FullRemoval($dirname . '/' . $entry);
     }
     // Clean up
     $dir->close();
     return @rmdir($dirname);
 }
コード例 #2
0
ファイル: Files.php プロジェクト: Dulciane/jaws
 /**
  * Deletes a file or directory
  *
  * @access  public
  * @param   string  $path       Where is it
  * @param   string  $filename   The name of the file
  * @return  bool    Returns true if file/directory was deleted without problems, if not, returns false
  */
 function Delete($path, $filename)
 {
     $path = trim($path, '/');
     $path = str_replace('..', '', $path);
     $file = $path . '/' . $filename;
     $fModel = $this->gadget->model->load('Files');
     $filename = $fModel->GetFileBrowserRootDir() . $file;
     $blackList = explode(',', $this->gadget->registry->fetch('black_list'));
     $blackList = array_map('strtolower', $blackList);
     require_once PEAR_PATH . 'File/Util.php';
     $realpath = File_Util::realpath($filename);
     if (!File_Util::pathInRoot($realpath, $fModel->GetFileBrowserRootDir()) || in_array(strtolower(basename($filename)), $blackList)) {
         $msgError = is_dir($filename) ? _t('FILEBROWSER_ERROR_CANT_DELETE_DIR', $file) : _t('FILEBROWSER_ERROR_CANT_DELETE_FILE', $file);
         $GLOBALS['app']->Session->PushLastResponse($msgError, RESPONSE_ERROR);
         return false;
     }
     if (is_file($filename)) {
         $return = @unlink($filename);
         if (!$return) {
             $GLOBALS['app']->Session->PushLastResponse(_t('FILEBROWSER_ERROR_CANT_DELETE_FILE', $file), RESPONSE_ERROR);
             return false;
         }
     } elseif (is_dir($filename)) {
         $return = Jaws_FileManagement::FullRemoval($filename);
         if (!$return) {
             $GLOBALS['app']->Session->PushLastResponse(_t('FILEBROWSER_ERROR_CANT_DELETE_DIR', $file), RESPONSE_ERROR);
             return false;
         }
     }
     return true;
 }