本文整理匯總了PHP中Symfony\Component\HttpFoundation\File\File::isReadable方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::isReadable方法的具體用法?PHP File::isReadable怎麽用?PHP File::isReadable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\File\File
的用法示例。
在下文中一共展示了File::isReadable方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setFile
/**
* 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;
}
示例2: setFile
/**
* 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;
}
示例3: importInfinityBoardAssets
/**
* 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.");
}
});
}