예제 #1
0
 public function fileInfo(string $dir, string $extension = NULL) : array
 {
     $dir = File::rpath($dir);
     if (is_dir($dir)) {
         $files = Factory::class('FileList')->files($dir, $extension);
         $dir = suffix($dir);
         $filesInfo = [];
         foreach ($files as $file) {
             $filesInfo[$file]['basename'] = pathInfos($dir . $file, 'basename');
             $filesInfo[$file]['size'] = filesize($dir . $file);
             $filesInfo[$file]['date'] = filemtime($dir . $file);
             $filesInfo[$file]['readable'] = is_readable($dir . $file);
             $filesInfo[$file]['writable'] = is_writable($dir . $file);
             $filesInfo[$file]['executable'] = is_executable($dir . $file);
             $filesInfo[$file]['permission'] = fileperms($dir . $file);
         }
         return $filesInfo;
     } elseif (is_file($dir)) {
         return (array) File::info($dir);
     } else {
         throw new FolderNotFoundException($dir);
     }
 }
예제 #2
0
function extension($file = '', $dote = false)
{
    if (!is_string($file)) {
        return false;
    }
    if (!is_bool($dote)) {
        $dote = false;
    }
    $dote = $dote === true ? '.' : '';
    return $dote . strtolower(pathInfos($file, "extension"));
}
예제 #3
0
 public function fileInfo($dir = '', $extension = '')
 {
     // Parametre kontrolleri yapılıyor. -------------------------------------------
     if (!is_string($dir)) {
         return Error::set(lang('Error', 'stringParameter', 'dir'));
     }
     if (!is_string($extension)) {
         $extension = '';
     }
     // ----------------------------------------------------------------------------
     if (is_dir($dir)) {
         $files = $this->files($dir, $extension);
         $dir = suffix($dir);
         $filesInfo = array();
         foreach ($files as $file) {
             $filesInfo[$file]['basename'] = pathInfos($dir . $file, 'basename');
             $filesInfo[$file]['size'] = filesize($dir . $file);
             $filesInfo[$file]['date'] = filemtime($dir . $file);
             $filesInfo[$file]['readable'] = is_readable($dir . $file);
             $filesInfo[$file]['writable'] = is_writable($dir . $file);
             $filesInfo[$file]['executable'] = is_executable($dir . $file);
             $filesInfo[$file]['permission'] = fileperms($dir . $file);
         }
         return $filesInfo;
     } elseif (is_file($dir)) {
         $fileinfo = File::info($dir);
         return (array) $fileinfo;
     } else {
         return Error::set(lang('Error', 'fileDirParameter', 'dir'));
     }
 }
예제 #4
0
 public function info($file = '')
 {
     if (!is_file($file)) {
         return Error::set('Error', 'fileParameter', 'file');
     }
     return (object) array('basename' => pathInfos($file, 'basename'), 'size' => filesize($file), 'date' => filemtime($file), 'readable' => is_readable($file), 'writable' => is_writable($file), 'executable' => is_executable($file), 'permission' => fileperms($file));
 }
예제 #5
0
 public function createZip(string $path, array $data) : bool
 {
     $path = File::rpath($path);
     $zip = new ZipArchive();
     $zipPath = suffix($path, ".zip");
     if (file_exists($zipPath)) {
         unlink($zipPath);
     }
     if (!is_dir($pathDirName = pathInfos($path, 'dirname'))) {
         Folder::create($pathDirName);
     }
     if ($zip->open($zipPath, ZipArchive::CREATE) !== true) {
         return false;
     }
     $status = '';
     if (!empty($data)) {
         foreach ($data as $key => $val) {
             if (is_numeric($key)) {
                 $file = $val;
                 $fileName = NULL;
             } else {
                 $file = $key;
                 $fileName = $val;
             }
             if (is_dir($file)) {
                 $allFiles = Folder::allFiles($file, true);
                 foreach ($allFiles as $f) {
                     $status = $zip->addFile($f, $f);
                 }
             } else {
                 $status = $zip->addFile($file, $fileName);
             }
         }
     }
     return $zip->close();
 }
예제 #6
0
 public function get(string $file) : \stdClass
 {
     $file = $this->rpath($file);
     if (!is_file($file)) {
         throw new FileNotFoundException($file);
     }
     return (object) ['basename' => pathInfos($file, 'basename'), 'size' => filesize($file), 'date' => filemtime($file), 'readable' => is_readable($file), 'writable' => is_writable($file), 'executable' => is_executable($file), 'permission' => fileperms($file)];
 }
예제 #7
0
function extension(string $file, bool $dote = false) : string
{
    $dote = $dote === true ? '.' : '';
    return $dote . strtolower(pathInfos($file, "extension"));
}