/** * Sets the file to stream. * * @param \SplFileInfo|string $file The file to stream * @param string $contentDisposition * @param bool $autoEtag * @param bool $autoLastModified * * @return BinaryFileResponse * * @throws FileException */ public function setFile($file, $contentDisposition = null, $etag = false, $lastModified = true) { if (!$file instanceof File) { if ($file instanceof \SplFileInfo) { $file = new File($file->getPathname()); } else { $file = new File((string) $file); } } if (!$file->isReadable()) { throw new FileException('File must be readable.'); } $this->file = $file; if ($etag === true) { $this->setAutoEtag(); } elseif (!empty($etag)) { $this->setEtag($etag); } if ($lastModified === true) { $this->setAutoLastModified(); } elseif (!empty($lastModified)) { is_numeric($lastModified) && ($lastModified = '@' . $lastModified); $this->setLastModified(new \DateTime($lastModified)); } if ($contentDisposition) { $this->setContentDisposition($contentDisposition); } return $this; }
/** * Sets the file to stream. * * @param \SplFileInfo|string $file The file to stream * @param string $contentDisposition * @param Boolean $autoEtag * @param Boolean $autoLastModified * * @return BinaryFileResponse * * @throws FileException */ public function setFile($file, $contentDisposition = null, $autoEtag = false, $autoLastModified = true) { $file = new File((string) $file); if (!$file->isReadable()) { throw new FileException('File must be readable.'); } $this->file = $file; if ($autoEtag) { $this->setAutoEtag(); } if ($autoLastModified) { $this->setAutoLastModified(); } if ($contentDisposition) { $this->setContentDisposition($contentDisposition); } return $this; }
/** * Imports board attachments. * * @return void */ public function importInfinityBoardAssets() { $this->info("\tImporting board assets ..."); BoardAsset::whereDoesntHave('flagPosts')->forceDelete(); Board::orderBy('board_uri', 'asc')->chunk(1, function ($boards) { foreach ($boards as $board) { $this->line("\t\tImporting assets from /{$board->board_uri}/"); $flagsMade = 0; $bannersMade = 0; # FLAGS $flagsPath = "{$this->targetLocation}/static/custom-flags/{$board->board_uri}/"; $flagSerPath = "{$this->targetLocation}/{$board->board_uri}/flags.ser"; $flags = []; if (file_exists($flagSerPath)) { try { $flags = @unserialize(@file_get_contents("{$this->targetLocation}/{$board->board_uri}/flags.ser")); } catch (\Exception $e) { $this->warn("\t\t\tFailed to unserialize flags.ser"); } if (is_array($flags) && count($flags)) { foreach ($flags as $flagFile => $flagName) { $flag = new File("{$flagsPath}{$flagFile}.png", false); if ($flag->isReadable()) { $storage = FileStorage::storeUpload($flag); $asset = $board->assets()->create(['file_id' => $storage->file_id, 'asset_type' => "board_flags", 'asset_name' => $flagName]); ++$flagsMade; } } } } # BANNERS $bannersPath = "{$this->targetLocation}/static/banners/{$board->board_uri}/"; if (is_readable($bannersPath)) { $banners = array_filter(scandir($bannersPath), function ($item) use($bannersPath) { return !is_dir("{$bannersPath}{$item}"); }); foreach ($banners as $bannerName) { $banner = new File("{$bannersPath}{$bannerName}", false); if ($banner->isReadable() && !!FileFacade::get($banner)) { $storage = FileStorage::storeUpload($banner); $asset = $board->assets()->create(['file_id' => $storage->file_id, 'asset_type' => "board_banner", 'asset_name' => null]); ++$bannersMade; } } } $this->line("\t\tImported {$flagsMade} flags and {$bannersMade} banners."); } }); }