Ejemplo n.º 1
0
/**
	List all files in a directory and store various informations about them in the resulting array.

	@param $sPath Path to the directory to list.
	@param $aMimeIcons List of icons for each known mime types.
	@return array The verbose list of files.
	@todo links pointing to nothing fail
	@todo handle empty $aMimeIcons properly
*/
function fs_list_directory_contents($sPath, $aMimeIcons = array())
{
    try {
        $oDirectory = new DirectoryIterator($sPath);
    } catch (Exception $e) {
        // The folder doesn't exist, so there is no files to list.
        return array();
    }
    $oFileInfo = new finfo(FILEINFO_MIME);
    $aFiles = array();
    foreach ($oDirectory as $oFile) {
        if ($oFile->isDot()) {
            continue;
        }
        $sFilename = $oFile->getFilename();
        $sExt = strrchr($sFilename, '.');
        $iSize = $oFile->getSize();
        $sMimeType = $oFileInfo->file($oFile->getRealPath());
        $iMTime = $oFile->getMTime();
        // Folder is preferred
        if ($sMimeType == 'directory') {
            $sMimeType = 'folder';
        }
        $aFiles[$sFilename] = array('icon' => ui_mime_to_icon($sMimeType, $aMimeIcons), 'filename' => $sFilename, 'ext' => $sExt === false ? null : substr($sExt, 1), 'size' => $iSize, 'husize' => human_size($iSize), 'mimetype' => $sMimeType, 'mtime' => $iMTime, 'humtime' => human_date($iMTime));
    }
    ksort($aFiles);
    return $aFiles;
}
 /**
  * Convert bytes to kilobytes, megabytes, etc
  *
  * @param int $bytes
  * @return string $bytes in human-readable form, eg "50.2 MB"
  */
 public function humanize($bytes)
 {
     return human_size($bytes);
 }
Ejemplo n.º 3
0
        $expired = !isset($_GET['apc_show_expired']) && $item['ttl'] > 0 && get_key($item, 'mtime', 'modification_time') + $item['ttl'] < time();
        if (!preg_match(get_selector(), get_key($item, 'key', 'info')) || $expired) {
            continue;
        }
        ?>
						<tr>
							<td><?php 
        echo get_key($item, 'key', 'info');
        ?>
</td>
							<td><?php 
        echo $item['nhits'];
        ?>
</td>
							<td><?php 
        echo human_size($item['mem_size']);
        ?>
</td>
							<td><?php 
        echo $item['ttl'];
        ?>
</td>
							<td><?php 
        echo date('Y-m-d H:i', get_key($item, 'mtime', 'modification_time') + $item['ttl']);
        ?>
</td>
							<td>
								<a href="?action=apc_delete&selector=<?php 
        echo urlencode('^' . get_key($item, 'key', 'info') . '$');
        ?>
">Delete</a>
Ejemplo n.º 4
0
 /**
  * Получение списка файлов
  */
 public function get_list($server_id = 0)
 {
     if (!$this->_check_server($server_id)) {
         $this->_send_error($this->_error);
         return;
     }
     $this->form_validation->set_rules('dir', lang('directory'), 'trim|xss_clean');
     if ($this->form_validation->run() == false) {
         if (validation_errors()) {
             $this->_send_error(lang('web_ftp_form_error'));
             return false;
         }
     }
     $loc_dir = $this->_two_point_delete($this->input->post('dir', true));
     $loc_dir = empty($loc_dir) ? '/' : $loc_dir;
     $dir = get_ds_file_path($this->servers->server_data) . '/' . $loc_dir;
     // Данные для соединения
     $config = get_file_protocol_config($this->servers->server_data);
     try {
         $this->files->set_driver($config['driver']);
         $this->files->connect($config);
         $files = $this->files->list_files_full_info($dir);
     } catch (exception $e) {
         $this->_send_error($e->getMessage());
         return;
     }
     $return['dirs'] = array();
     $return['files'] = array();
     foreach ($files as &$file) {
         $file['file_size'] = human_size($file['file_size']);
         $file['file_time'] = unix_to_human($file['file_time'], true, 'ru');
         // Скрытие файлов (exe, dll и т.д.)
         if (!$this->_check_file_ext($file)) {
             continue;
         }
         // Директории впереди
         if ($file['type'] == 'd') {
             $file['file_size'] = '';
             $return['dirs'][] = $file;
         } else {
             $return['files'][] = $file;
         }
     }
     $this->_send_response(array('status' => 1, 'files' => array_merge($return['dirs'], $return['files'])));
 }