當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。