You are here

public function FMDiskFileSystem::getFiles in N1ED - Visual editor as CKEditor plugin with Bootstrap support 8.2

Gets a files list.

Overrides FMDiskFileSystemInterface::getFiles

File

src/Flmngr/FlmngrServer/fs/FMDiskFileSystem.php, line 173

Class

FMDiskFileSystem
Implements file system interface. Provides an interface to access file system (local disc FS). This is the correct module to replace if you want to implement some custom file system support (i. e. network file system like Amazon S3).

Namespace

Drupal\n1ed\Flmngr\FlmngrServer\fs

Code

public function getFiles($dirPath) {

  // with "/root_dir_name" in the start
  $fullPath = $this
    ->getAbsolutePath($dirPath);
  if (!is_dir($fullPath)) {
    throw new MessageException(Message::createMessage(Message::DIR_DOES_NOT_EXIST, $dirPath));
  }
  $fFiles = scandir($fullPath);
  if ($fFiles === FALSE) {
    throw new MessageException(FMMessage::createMessage(FMMessage::FM_DIR_CANNOT_BE_READ));
  }
  $files = [];
  for ($i = 0; $i < count($fFiles); $i++) {
    $fFile = $fFiles[$i];
    $fileFullPath = $fullPath . '/' . $fFile;
    if (is_file($fileFullPath)) {
      try {
        $imageInfo = $this
          ->getImageInfo($fileFullPath);
        list($previewFormat, $previewFile) = $this
          ->getImagePreview($fileFullPath, 159, 139);
        $previewData = '';
        while (!feof($previewFile)) {
          $previewData .= fread($previewFile, 8192);
        }
        fclose($previewFile);
        $preview = "data:" . $previewFormat . ";base64," . base64_encode($previewData);
      } catch (Exception $e) {
        $imageInfo = new ImageInfo();
        $imageInfo->width = NULL;
        $imageInfo->height = NULL;
      }
      $file = new FMFile($dirPath, $fFile, filesize($fileFullPath), filemtime($fileFullPath), $imageInfo);
      if ($preview != null) {
        $file->preview = $preview;
      }
      $files[] = $file;
    }
  }
  return $files;
}