Пример #1
0
 /**
  * Recursive copy
  *
  * Copies a file to another location or a complete directory
  *
  * @access  public
  * @param   string  $source  File source
  * @param   string  $dest    Destination path
  * @return  bool    Returns TRUE on success, FALSE on failure
  */
 function FullCopy($source, $dest)
 {
     // Simple copy for a file
     if (is_file($source)) {
         return copy($source, $dest);
     }
     // Make destination directory
     Jaws_Utils::mkdir($dest);
     // Loop through the folder
     $dir = @dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         if ($dest !== $source . '/' . $entry) {
             Jaws_FileManagement::FullCopy($source . '/' . $entry, $dest . '/' . $entry);
         }
     }
     // Clean up
     $dir->close();
     return true;
 }
Пример #2
0
 /**
  * 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;
 }