本文整理匯總了PHP中Symfony\Component\HttpFoundation\File\File::getFilename方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::getFilename方法的具體用法?PHP File::getFilename怎麽用?PHP File::getFilename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\File\File
的用法示例。
在下文中一共展示了File::getFilename方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getName
/**
* Get original name of file.
*
* @return string
*/
public function getName()
{
if ($this->file instanceof UploadedFile) {
return $this->file->getClientOriginalName();
}
return $this->file->getFilename();
}
示例2: saveImg
/**
* @param \Symfony\Component\HttpFoundation\File\File $img
* @param string $path
*
* @return string
*/
public function saveImg(File $img, $path)
{
$imageLib = new ImageLib();
$imageLib->load($path . $img->getFilename());
$outputImgName = md5($img->getFilename() . time()) . '.' . $img->getExtension();
//$imageLib->resizeImage(100, 100, array('crop', 'tr'), true);
$imageLib->saveImage($path . $outputImgName, 100);
return $outputImgName;
}
示例3: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{
$configs = $form->getAttribute('configs');
$datas = $form->getClientData();
if (!empty($datas)) {
if ($form->getAttribute('multiple')) {
$datas = is_scalar($datas) ? explode(',', $datas) : $datas;
$value = array();
foreach ($datas as $data) {
if (!$data instanceof File) {
$data = new File($form->getAttribute('rootDir') . '/' . $data);
}
$value[] = $configs['folder'] . '/' . $data->getFilename();
}
$value = implode(',', $value);
} else {
if (!$datas instanceof File) {
$datas = new File($form->getAttribute('rootDir') . '/' . $datas);
}
$value = $configs['folder'] . '/' . $datas->getFilename();
}
$view->set('value', $value);
}
$view->set('type', 'hidden')->set('configs', $form->getAttribute('configs'));
}
示例4: getResponse
/**
* @param Closure $callback
* @param InterventionRequest $interventionRequest
* @return Response
*/
public function getResponse(Closure $callback, InterventionRequest $interventionRequest)
{
try {
$this->cacheFile = new File($this->cacheFilePath);
$response = new Response(file_get_contents($this->cacheFile->getPathname()), Response::HTTP_OK, ['Content-Type' => $this->cacheFile->getMimeType(), 'Content-Disposition' => 'filename="' . $this->realImage->getFilename() . '"', 'X-Generator-Cached' => true]);
$response->setLastModified(new \DateTime(date("Y-m-d H:i:s", $this->cacheFile->getMTime())));
} catch (FileNotFoundException $e) {
if (is_callable($callback)) {
$image = $callback($interventionRequest);
if ($image instanceof Image) {
$this->saveImage($image);
$this->cacheFile = new File($this->cacheFilePath);
if (null !== $this->dispatcher) {
// create the ImageSavedEvent and dispatch it
$event = new ImageSavedEvent($image, $this->cacheFile);
$this->dispatcher->dispatch(ImageSavedEvent::NAME, $event);
}
// send HTTP header and output image data
$response = new Response(file_get_contents($this->cacheFile->getPathname()), Response::HTTP_OK, ['Content-Type' => $image->mime(), 'Content-Disposition' => 'filename="' . $this->realImage->getFilename() . '"', 'X-Generator-First-Render' => true]);
$response->setLastModified(new \DateTime('now'));
} else {
throw new \RuntimeException("Image is not a valid InterventionImage instance.", 1);
}
} else {
throw new \RuntimeException("No image handle closure defined", 1);
}
}
$this->initializeGarbageCollection();
return $response;
}
示例5: handle
/**
* Handle request to convert it to a Response object.
*/
public function handle()
{
try {
if (!$this->request->query->has('image')) {
throw new FileNotFoundException("No valid image path found in URI", 1);
}
$nativePath = $this->configuration->getImagesPath() . '/' . $this->request->query->get('image');
$this->nativeImage = new File($nativePath);
$this->parseQuality();
if ($this->configuration->hasCaching()) {
$cache = new FileCache($this->request, $this->nativeImage, $this->configuration->getCachePath(), $this->logger, $this->quality, $this->configuration->getTtl(), $this->configuration->getGcProbability(), $this->configuration->getUseFileChecksum());
$cache->setDispatcher($this->dispatcher);
/** @var Response response */
$this->response = $cache->getResponse(function (InterventionRequest $interventionRequest) {
return $interventionRequest->processImage();
}, $this);
} else {
$this->processImage();
$this->response = new Response((string) $this->image->encode(null, $this->quality), Response::HTTP_OK, ['Content-Type' => $this->image->mime(), 'Content-Disposition' => 'filename="' . $this->nativeImage->getFilename() . '"', 'X-Generator-First-Render' => true]);
$this->response->setLastModified(new \DateTime('now'));
}
} catch (FileNotFoundException $e) {
$this->response = $this->getNotFoundResponse($e->getMessage());
} catch (\RuntimeException $e) {
$this->response = $this->getBadRequestResponse($e->getMessage());
}
}
示例6: getSplitFiles
/**
* @return array
*/
public function getSplitFiles()
{
$file = new File($this->archivePath);
$finder = new Finder();
$finder->files()->in(dirname($this->archivePath))->notName($file->getFilename())->sortByModifiedTime();
return iterator_to_array($finder);
}
示例7: setFileAttribute
public function setFileAttribute(\Symfony\Component\HttpFoundation\File\File $file)
{
$this->attributes['file'] = $file;
$this->original_name = $file instanceof UploadedFile ? $file->getClientOriginalName() : $file->getFilename();
$this->size = $file->getSize();
$this->content_type = $file->getMimeType();
}
示例8: setContentDisposition
/**
* Sets the Content-Disposition header with the given filename.
*
* @param string $disposition ResponseHeaderBag::DISPOSITION_INLINE or ResponseHeaderBag::DISPOSITION_ATTACHMENT
* @param string $filename Optionally use this filename instead of the real name of the file
* @param string $filenameFallback A fallback filename, containing only ASCII characters. Defaults to an automatically encoded filename
*
* @return BinaryFileResponse
*/
public function setContentDisposition($disposition, $filename = '', $filenameFallback = '')
{
if ($filename === '') {
$filename = $this->file->getFilename();
}
$dispositionHeader = $this->headers->makeDisposition($disposition, $filename, $filenameFallback);
$this->headers->set('Content-Disposition', $dispositionHeader);
return $this;
}
示例9: setImageFile
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*
* @return $this
*/
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
$this->modifiedAt = new \DateTime('now');
$this->fileName = $image->getFilename();
}
return $this;
}
示例10: setImageFile
public function setImageFile(File $imageFile)
{
if ($imageFile instanceof File) {
$this->imageFile = $imageFile;
if (!$this->name) {
$this->name = $imageFile->getFilename();
}
$this->updatedAt = new \DateTime('now');
}
}
示例11: transform
/**
* @inheritDoc
*/
public function transform(File $file, ResourceAnnotationInterface $config)
{
/** @var ResourceImage $config */
//create copy with image extension instead of .tmp, required to save with Imagine
$newName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $file->getFilename() . '.' . $file->guessExtension();
if (copy($file->getRealPath(), $newName)) {
$newFile = new File($newName);
return $this->imageResize($newFile, $config->maxWith, $config->maxHeight, $config->enlarge, $config->keepRatio);
} else {
return $file;
}
}
示例12: fromFile
/**
* Creates a file object from a file on the disk.
*/
public function fromFile($filePath)
{
if ($filePath === null) {
return;
}
$file = new FileObj($filePath);
$this->file_name = $file->getFilename();
$this->file_size = $file->getSize();
$this->content_type = $file->getMimeType();
$this->disk_name = $this->getDiskName();
$this->putFile($uploadedFile->getRealPath(), $this->disk_name);
}
示例13: setAvatarFile
/**
* Set the avatar of the object to be a specific file
*
* @param File|null $file The avatar file
* @return self
*/
public function setAvatarFile($file)
{
if ($file) {
// We don't use File's fread() because it's unavailable in less
// recent PHP versions
$path = $file->getPath() . '/' . $file->getFilename();
$content = file_get_contents($path);
$path = $this->getAvatarPath(null, false, false);
$filename = $this->getAvatarFileName($content);
$file->move(DOC_ROOT . $path, $filename);
$this->setAvatar($path . $filename);
}
return $this;
}
示例14: validateFileExtension
public static function validateFileExtension(File $file, $extensions = array())
{
if (empty($extensions)) {
$extensions = self::getSecureFileExtensions();
}
if ($file instanceof UploadedFile) {
$filename = $file->getClientOriginalName();
} else {
$filename = $file->getFilename();
}
$errors = array();
$regex = '/\\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
if (!preg_match($regex, $filename)) {
$errors[] = "隻允許上傳以下擴展名的文件:" . $extensions;
}
return $errors;
}
示例15: prepareResponse
private function prepareResponse(File $file, $filename = null)
{
$mimeType = $file->getMimeType();
if ($mimeType == 'application/pdf') {
$disposition = 'inline';
} else {
$disposition = 'attachment';
}
$response = new Response();
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-Type', $mimeType);
$response->headers->set('Content-Disposition', $disposition . '; filename="' . ($filename ? $filename : $file->getFilename()) . '"');
$response->headers->set('Content-Length', $file->getSize());
$response->sendHeaders();
readfile($file);
return $response;
}