当前位置: 首页>>代码示例>>PHP>>正文


PHP File\File类代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\File的典型用法代码示例。如果您正苦于以下问题:PHP File类的具体用法?PHP File怎么用?PHP File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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();
 }
开发者ID:AniartUA,项目名称:crm,代码行数:7,代码来源:File.php

示例2: resize

 /**
  * Resize image
  *
  * @param  int $width Thumbnail width
  * @param  int $height Thumbnail height
  * @param  string $fileName Source file name
  * @return \Response Image content
  */
 public function resize($width, $height, $fileName)
 {
     $destFile = $this->createThumb($width, $height, $fileName);
     $fileContent = $this->getFileContent($destFile);
     $file = new SymfonyFile($destFile);
     return response()->make($fileContent, 200, ['content-type' => $file->getMimeType()]);
 }
开发者ID:namnv609,项目名称:l5-fly-thumb,代码行数:15,代码来源:L5FlyThumb.php

示例3: process

 public function process(File $file, Image $image)
 {
     $imageData = $this->intervention->make($file->getRealPath());
     $imageData->brightness($this->brightness);
     $imageData->blur($this->blur);
     $imageData->save(null, $this->compression);
 }
开发者ID:tippingcanoe,项目名称:imager,代码行数:7,代码来源:Blur.php

示例4: testGetDefaultExtensionIsBasedOnMimeType

 public function testGetDefaultExtensionIsBasedOnMimeType()
 {
     $file = new File(__DIR__ . '/Fixtures/test');
     $guesser = $this->createMockGuesser($file->getPath(), 'image/gif');
     MimeTypeGuesser::getInstance()->register($guesser);
     $this->assertEquals('.gif', $file->getDefaultExtension());
 }
开发者ID:netixpro,项目名称:symfony,代码行数:7,代码来源:FileTest.php

示例5: getName

 /**
  * Get original name of file.
  *
  * @return string
  */
 public function getName()
 {
     if ($this->file instanceof UploadedFile) {
         return $this->file->getClientOriginalName();
     }
     return $this->file->getFilename();
 }
开发者ID:Vooodoo,项目名称:MediaBundle,代码行数:12,代码来源:FileInfo.php

示例6: regenerateSpeakerPhotoPath

 private function regenerateSpeakerPhotoPath($speaker)
 {
     // If speaker photo does not exist, null it out and return.
     if (!$this->fileExists($speaker['photo_path'])) {
         echo "[info] {$speaker['name']}'s photo was not found in file system. Removing record of it from profile." . PHP_EOL;
         $this->execute("UPDATE users SET photo_path = '' WHERE id = {$speaker['id']}");
         return;
     }
     // Need to guess extension. Cannot trust current file extensions.
     $file = new File(__DIR__ . '/../web/uploads/' . $speaker['photo_path']);
     $extension = $file->guessExtension();
     // Otherwise, generate a new filename.
     $generator = new PseudoRandomStringGenerator(new Factory());
     $newFileName = $generator->generate(40) . '.' . $extension;
     $oldFilePath = __DIR__ . '/../web/uploads/' . $speaker['photo_path'];
     $newFilePath = __DIR__ . '/../web/uploads/' . $newFileName;
     // If photo name is changed in file system, update record in database.
     if (rename($oldFilePath, $newFilePath)) {
         try {
             $this->execute("UPDATE users SET photo_path = '{$newFileName}' WHERE id = '{$speaker['id']}'");
             echo "[info] Regenerated photo path for {$speaker['name']}." . PHP_EOL;
         } catch (\Exception $e) {
             // If update fails for any reason, revert filename in file system.
             rename($newFilePath, $oldFilePath);
         }
     }
 }
开发者ID:noahd1,项目名称:opencfp,代码行数:27,代码来源:20150519122926_reset_photo_paths.php

示例7: handle

 protected function handle()
 {
     $request = $this->getRequest();
     $posts = $request->request;
     $file_path = $posts->get('image_path');
     $x = $posts->get('x');
     $y = $posts->get('y');
     $w = $posts->get('w');
     $h = $posts->get('h');
     $path_info = pathinfo($file_path);
     $imagine = new Imagine();
     $raw_image = $imagine->open($file_path);
     $large_image = $raw_image->copy();
     $large_image->crop(new Point($x, $y), new Box($w, $h));
     $large_file_path = "{$path_info['dirname']}/{$path_info['filename']}_large.{$path_info['extension']}";
     $large_image->save($large_file_path, array('quality' => 70));
     $origin_dir_name = $path_info['dirname'];
     $new_directory = str_replace('/tmp', '', $origin_dir_name);
     $new_file = new File($large_file_path);
     $new_file->move($new_directory, "{$path_info['filename']}.{$path_info['extension']}");
     $container = $this->getContainer();
     $cdn_url = $container->getParameter('cdn_url');
     $new_uri = $cdn_url . '/upload/' . $path_info['filename'] . '.' . $path_info['extension'];
     @unlink($large_file_path);
     @unlink($file_path);
     return new JsonResponse(array('picture_uri' => $new_uri));
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:27,代码来源:ActionIconCrop.php

示例8: boot

 protected static function boot()
 {
     parent::boot();
     static::updating(function ($model) {
         $changed = $model->getDirty();
         if (isset($changed['name'])) {
             $slug = $model->gallery->slug;
             $path = public_path() . '/gallery_assets/galleries/' . $slug;
             //Get old file
             $oldPath = $path . '/' . $model->file;
             $file = new File($oldPath);
             //Set the new file with original extension
             $newName = strtolower(str_slug($model->name) . '_' . str_random(5)) . '.' . $file->getExtension();
             $renamed = $path . '/' . $newName;
             //Rename asset
             if (rename($file, $renamed)) {
                 $model->setAttribute('file', $newName);
                 return true;
             } else {
                 return false;
             }
         }
         return true;
     });
     static::deleting(function ($model) {
         $slug = $model->gallery->slug;
         $path = public_path() . '/gallery_assets/galleries/' . $slug;
         $oldPath = $path . '/' . $model->file;
         $file = new File($oldPath);
         @unlink($file);
         //@ to prevent errors
         return true;
     });
 }
开发者ID:Krato,项目名称:kgallery,代码行数:34,代码来源:PhotoEvents.php

示例9: run

 public function run(File $file)
 {
     $image = $this->intervention->make($file->getRealPath());
     $image->orientate();
     $image->save(null, 100);
     $image->destroy();
 }
开发者ID:bmartel,项目名称:phperclip,代码行数:7,代码来源:FixRotation.php

示例10: 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);
 }
开发者ID:ronisaha,项目名称:CloudBackupBundle,代码行数:10,代码来源:BaseSplitter.php

示例11: 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'));
 }
开发者ID:r4cker,项目名称:GenemuFormBundle,代码行数:28,代码来源:FileType.php

示例12: testCreateImagesFromApplicationOctetStream

 /**
  * @param $imageFileObject
  * @param $finalMimeType
  *
  * @dataProvider imagesAsOctetStreamProvider
  */
 public function testCreateImagesFromApplicationOctetStream(File $imageFileObject, $finalMimeType)
 {
     $this->assertEquals('application/octet-stream', $imageFileObject->getMimeType());
     $image = $this->imageManager->createImage($imageFileObject);
     $this->assertInstanceOf('Elcodi\\Component\\Media\\Entity\\Interfaces\\ImageInterface', $image);
     $this->assertEquals($finalMimeType, $image->getContentType());
 }
开发者ID:axelvnk,项目名称:elcodi,代码行数:13,代码来源:ImageManagerTest.php

示例13: move

 /**
  * @param FormEvent $event
  */
 public function move(FormEvent $event)
 {
     $data = $event->getData();
     if (is_callable($this->dstDir)) {
         $dstDir = call_user_func($this->dstDir, $event->getForm()->getParent()->getData());
     } else {
         $dstDir = $this->dstDir;
     }
     if (!empty($data)) {
         foreach ($data as $key => $path) {
             // First check if the file is still in tmp directory
             $originalFilename = $this->rootDir . '/../web/' . trim($path, '/');
             $destinationFilename = $this->rootDir . '/../web/' . trim($dstDir, '/') . '/' . basename($path);
             $webPath = rtrim($dstDir, '/') . '/' . basename($path);
             if (file_exists($originalFilename)) {
                 // if it does, then move it to the destination and update the data
                 $file = new File($originalFilename);
                 $file->move(dirname($destinationFilename));
                 // modify the form data with the new path
                 $data[$key] = $webPath;
             } else {
                 // otherwise check if it is already on the destination
                 if (file_exists($destinationFilename)) {
                     // if it does, simply modify the form data with the new path
                     // modify the form data with the new path
                     $data[$key] = $webPath;
                 } else {
                     // TODO :  check if we need to throw an exception here
                     unset($data[$key]);
                 }
             }
         }
         $event->setData($data);
     }
 }
开发者ID:leapt,项目名称:admin-bundle,代码行数:38,代码来源:MultiUploadSubscriber.php

示例14: 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;
 }
开发者ID:unionbt,项目名称:hanpaimall,代码行数:41,代码来源:BinaryFileResponse.php

示例15: createImage

 /**
  * Given a single File, assuming is an image, create a new
  * Image object containing all needed information.
  *
  * This method also persists and flush created entity
  *
  * @param File $file File where to get the image
  *
  * @return ImageInterface Image created
  *
  * @throws InvalidImageException File is not an image
  */
 public function createImage(File $file)
 {
     $fileMime = $file->getMimeType();
     if ('application/octet-stream' === $fileMime) {
         $imageSizeData = getimagesize($file->getPathname());
         $fileMime = $imageSizeData['mime'];
     }
     if (strpos($fileMime, 'image/') !== 0) {
         throw new InvalidImageException();
     }
     $extension = $file->getExtension();
     if (!$extension && $file instanceof UploadedFile) {
         $extension = $file->getClientOriginalExtension();
     }
     /**
      * @var ImageInterface $image
      */
     $image = $this->imageFactory->create();
     if (!isset($imageSizeData)) {
         $imageSizeData = getimagesize($file->getPathname());
     }
     $name = $file->getFilename();
     $image->setWidth($imageSizeData[0])->setHeight($imageSizeData[1])->setContentType($fileMime)->setSize($file->getSize())->setExtension($extension)->setName($name);
     return $image;
 }
开发者ID:pramoddas,项目名称:elcodi,代码行数:37,代码来源:ImageManager.php


注:本文中的Symfony\Component\HttpFoundation\File\File类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。