コード例 #1
0
ファイル: FileExplorer.php プロジェクト: renanrmelo/cvsgit
 /**
  * Mostra os Itens de Um diretório
  * @param string  $sDiretorio        -> Diretório a ser pesquisado
  * @param boolean $lMostraDiretorios -> mostra pastas
  * @param boolean $lMostraArquivos   -> mostra arquivos
  * @param string  $sRegexpIgnorar    -> expressão regular para ignorar casos Ex. $sRegexpIgnorar = "/CVS/";
  * @param boolean $lRecursivo        -> pesquisar diretório recursivamente
  * @return $aRetorno - Array contendo a string dos itens encontrados nos diretórios
  */
 public static function listarDiretorio($sDiretorio, $lMostraDiretorios = true, $lMostraArquivos = true, $sRegexpIgnorar = null, $lRecursivo = false)
 {
     $aRetorno = array();
     if (!is_dir($sDiretorio)) {
         throw new Exception("Nao e um diretorio.");
     }
     if (!is_readable($sDiretorio)) {
         throw new Exception("Diretorio não Pode ser Lido.");
     }
     $rDiretorio = opendir($sDiretorio);
     if (!$rDiretorio) {
         throw new Exception('Nao foi possivel abrir o Diretorio');
     }
     while (($sArquivo = readdir($rDiretorio)) !== false) {
         // echo "\nIgnorar Diretorio: $sDiretorio/$sArquivo - " . is_dir("$sDiretorio/$sArquivo") ." - ". !$lMostraDiretorios;
         if (is_dir("{$sDiretorio}/{$sArquivo}") && !$lMostraDiretorios) {
             continue;
         }
         // echo "\nIgnorar Arquivo: $sDiretorio/$sArquivo - " .  !is_dir("$sDiretorio/$sArquivo") . " - " . !$lMostraArquivos;
         //var_dump("$sDiretorio/$sArquivo",is_dir("$sDiretorio/$sArquivo"), $lMostraDiretorios, $lMostraArquivos);
         if (!is_dir("{$sDiretorio}/{$sArquivo}") && !$lMostraArquivos) {
             continue;
         }
         $lAchouExpressao = is_null($sRegexpIgnorar) ? false : preg_match($sRegexpIgnorar, $sArquivo);
         if ($sArquivo == "." || $sArquivo == ".." || $lAchouExpressao) {
             continue;
         }
         if (is_dir("{$sDiretorio}/{$sArquivo}") && is_readable("{$sDiretorio}/{$sArquivo}") && $lRecursivo) {
             $aRetorno = array_merge($aRetorno, FileExplorer::listarDiretorio("{$sDiretorio}/{$sArquivo}", $lMostraDiretorios, $lMostraArquivos, $sRegexpIgnorar, $lRecursivo));
         }
         $aRetorno[] = "{$sDiretorio}/{$sArquivo}";
     }
     return $aRetorno;
 }
コード例 #2
0
 /**
  * Rename file
  */
 public function admin_rename()
 {
     if ($this->request->is('post')) {
         $data =& $this->request->data;
         $this->getFileExplorer($data['config'])->dir($data['dir']);
         if ($this->FileExplorer->rename($data['file'], $data['file_new'])) {
             $this->Session->setFlash(__("Renamed %s to %s", $data['file'], $data['file_new']), 'success');
         } else {
             $this->Session->setFlash(__("Renaming failed"), 'error');
         }
     } else {
         $this->request->data = array('name' => basename($this->_file), 'dir' => $this->_dir, 'file' => $this->_file, 'config' => $this->_config);
     }
 }
コード例 #3
0
ファイル: Config.php プロジェクト: incube/base
 /** Write a file in a specific format to a specific location
  *
  * @param string $path 
  * @param array $data */
 public function save($path, array $data)
 {
     $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
     switch ($ext) {
         case "ser":
             FileExplorer::write($path, serialize($data));
             break;
         default:
             trigger_error(__CLASS__ . " doesn't support {$ext} filetype.");
     }
 }
コード例 #4
0
 public function __construct(FileExplorer &$x, $filepath, $create = false, $mode = 0755)
 {
     $this->_dir = $x->dir();
     $this->_File = new File($filepath, $create, $mode);
 }