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


PHP UploadedFile::getSize方法代码示例

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


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

示例1: orientate

 /**
  * Orientate the image.
  *
  * @param UploadedFile $file
  * @param              $orientation
  * @return UploadedFile
  */
 protected function orientate(UploadedFile $file, $orientation)
 {
     $image = imagecreatefromjpeg($file->getRealPath());
     switch ($orientation) {
         case 2:
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 3:
             $image = imagerotate($image, 180, 0);
             break;
         case 4:
             $image = imagerotate($image, 180, 0);
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 5:
             $image = imagerotate($image, -90, 0);
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 6:
             $image = imagerotate($image, -90, 0);
             break;
         case 7:
             $image = imagerotate($image, 90, 0);
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 8:
             $image = imagerotate($image, 90, 0);
             break;
     }
     imagejpeg($image, $file->getRealPath(), 90);
     return new UploadedFile($file->getRealPath(), $file->getClientOriginalName(), $file->getMimeType(), $file->getSize());
 }
开发者ID:AkibaTech,项目名称:files-module,代码行数:39,代码来源:FileRotator.php

示例2: handleUploadedFile

 /**
  * Handles an uploaded file by putting it in the $targetDir.
  * 
  * @param UploadedFile $uploadedFile File object that has been uploaded - usually taken from Request object.
  * @param string $targetDir [optional] Where to (relatively to the storage root dir) put the file?
  * @param array $allowed [optional] What files are allowed? If not matching then will throw exception.
  * @param int $maxFileSize [optional] What is the maximum allowed file size for this file?
  * @return File
  */
 public function handleUploadedFile(UploadedFile $uploadedFile, $targetDir = '/', array $allowed = array(), $maxFileSize = 0)
 {
     array_walk($allowed, function ($ext) {
         return strtolower($ext);
     });
     $targetDir = trim($targetDir, '/');
     $targetDir = $this->path . $targetDir . (empty($targetDir) ? '' : '/');
     $filenameElements = explode('.', $uploadedFile->getClientOriginalName());
     $extension = array_pop($filenameElements);
     $extension = strtolower($extension);
     $filename = implode('.', $filenameElements);
     $targetName = StringUtils::fileNameFriendly($filename . '-' . StringUtils::random() . '.' . $extension);
     $targetPath = $targetDir . $targetName;
     // create unique file name
     while (file_exists($targetPath)) {
         $targetName = StringUtils::fileNameFriendly($filename . '-' . StringUtils::random() . '.' . $extension);
         $targetPath = $targetDir . $targetName;
     }
     // basic check for allowed type
     if (!empty($allowed) && !in_array($extension, $allowed)) {
         throw new FileException('The uploaded file is not of a valid type (allowed: ' . implode(', ', $allowed) . ').');
     }
     // basic check for max allowed size
     if ($maxFileSize && $uploadedFile->getSize() > $maxFileSize) {
         throw new FileException('The uploaded file is too big (max allowed size is ' . StringUtils::bytesToString($maxFileSize) . ').');
     }
     try {
         $movedFile = $uploadedFile->move(rtrim($targetDir, '/'), $targetName);
     } catch (SfFileException $e) {
         // if exception thrown then convert it to our exception
         throw new FileException($e->getMessage(), $e->getCode());
     }
     $file = $this->convertSfFileToStorageFile($movedFile);
     return $file;
 }
开发者ID:splot,项目名称:framework-extra-module,代码行数:44,代码来源:SimpleStorage.php

示例3: convertFieldValueFromForm

 /**
  * {@inheritdoc}
  *
  * @param null|\Symfony\Component\HttpFoundation\File\UploadedFile $data
  */
 public function convertFieldValueFromForm($data)
 {
     if ($data === null) {
         return null;
     }
     return array("inputUri" => $data->getRealPath(), "fileName" => $data->getClientOriginalName(), "fileSize" => $data->getSize());
 }
开发者ID:eab-dev,项目名称:NetgenEzFormsBundle,代码行数:12,代码来源:Image.php

示例4: testGetSize

 public function testGetSize()
 {
     $file = new UploadedFile(__DIR__ . '/Fixtures/test.gif', 'original.gif', 'image/gif', filesize(__DIR__ . '/Fixtures/test.gif'), null);
     $this->assertEquals(filesize(__DIR__ . '/Fixtures/test.gif'), $file->getSize());
     $file = new UploadedFile(__DIR__ . '/Fixtures/test', 'original.gif', 'image/gif');
     $this->assertEquals(filesize(__DIR__ . '/Fixtures/test'), $file->getSize());
 }
开发者ID:laubosslink,项目名称:lab,代码行数:7,代码来源:UploadedFileTest.php

示例5: process

 public function process(UploadedFile $file)
 {
     // File extension
     $this->extension = $file->getClientOriginalExtension();
     // Mimetype for the file
     $this->mimetype = $file->getMimeType();
     // Current user or 0
     $this->user_id = Auth::user() ? Auth::user()->id : 0;
     $this->size = $file->getSize();
     list($this->path, $this->filename) = $this->upload($file);
     $this->save();
     // Check to see if image thumbnail generation is enabled
     if (static::$app['config']->get('cabinet::image_manipulation')) {
         $thumbnails = $this->generateThumbnails($this->path, $this->filename);
         $uploads = array();
         foreach ($thumbnails as $thumbnail) {
             $upload = new $this();
             $upload->filename = $thumbnail->fileSystemName;
             $upload->path = static::$app['config']->get('cabinet::upload_folder_public_path') . $this->dateFolderPath . $thumbnail->fileSystemName;
             // File extension
             $upload->extension = $thumbnail->getClientOriginalExtension();
             // Mimetype for the file
             $upload->mimetype = $thumbnail->getMimeType();
             // Current user or 0
             $upload->user_id = $this->user_id;
             $upload->size = $thumbnail->getSize();
             $upload->parent_id = $this->id;
             $upload->save();
             $uploads[] = $upload;
         }
         $this->children = $uploads;
     }
 }
开发者ID:andrewelkins,项目名称:cabinet,代码行数:33,代码来源:CabinetUpload.php

示例6: validateMaxSize

 public function validateMaxSize($attribute, UploadedFile $value, $parameters)
 {
     $mediaPath = public_path(config('asgard.media.config.files-path'));
     $folderSize = $this->getDirSize($mediaPath);
     preg_match('/([0-9]+)/', $folderSize, $match);
     return $match[0] + $value->getSize() < config('asgard.media.config.max-total-size');
 }
开发者ID:Houbsi,项目名称:Media,代码行数:7,代码来源:MaxFolderSizeValidator.php

示例7: uploadFile

 /**
  * Upload provided file and create matching FileRecord object
  *
  * @param UploadedFile $file
  * @param $clientIp
  * @return FileRecord
  */
 public function uploadFile(UploadedFile $file, $clientIp)
 {
     $extension = Str::lower($file->getClientOriginalExtension());
     $generatedName = $this->generateName($extension);
     // Create SHA-256 hash of file
     $fileHash = hash_file('sha256', $file->getPathname());
     // Check if file already exists
     $existingFile = FileRecord::where('hash', '=', $fileHash)->first();
     if ($existingFile) {
         return $existingFile;
     }
     // Query previous scans in VirusTotal for this file
     if (config('virustotal.enabled') === true) {
         $this->checkVirusTotalForHash($fileHash);
     }
     // Get filesize
     $filesize = $file->getSize();
     // Check max upload size
     $maxUploadSize = config('upload.max_size');
     if ($filesize > $maxUploadSize) {
         throw new MaxUploadSizeException();
     }
     // Move the file
     $uploadDirectory = config('upload.directory');
     $file->move($uploadDirectory, $generatedName);
     // Create the record
     /** @var FileRecord $record */
     $record = FileRecord::create(['client_name' => $file->getClientOriginalName(), 'generated_name' => $generatedName, 'filesize' => $filesize, 'hash' => $fileHash, 'uploaded_by_ip' => $clientIp]);
     return $record;
 }
开发者ID:kimoi,项目名称:madokami.com,代码行数:37,代码来源:FileUpload.php

示例8: getFileArray

 /**
  * converts UploadedFile to $_FILES array
  *
  * @return array
  */
 public function getFileArray()
 {
     $array = array('name' => $this->uploaded_file->getClientOriginalName(), 'type' => $this->uploaded_file->getClientMimeType(), 'tmp_name' => $this->uploaded_file->getPath() . $this->getOSDirectorySeparator() . $this->uploaded_file->getFilename(), 'error' => $this->uploaded_file->getError(), 'size' => $this->uploaded_file->getSize(), 'dimension' => array('width' => 0, 'height' => 0));
     if (preg_match('/^image/', $array['type'])) {
         list($array['dimension']['width'], $array['dimension']['height']) = getimagesize($this->uploaded_file);
     }
     return $array;
 }
开发者ID:RSSfeed,项目名称:UploadBundle,代码行数:13,代码来源:HandleUpload.php

示例9: validate

 /**
  * Checks if the passed value is valid.
  *
  * @param UploadedFile   $file      The value that should be validated
  * @param Constraint     $constraint The constraint for the validation
  */
 public function validate($file, Constraint $constraint)
 {
     if (!in_array($file->getMimeType(), $this->mimeTypes)) {
         $this->context->buildViolation($constraint->messageMimeTypes)->atPath('file')->addViolation();
     }
     if ($file->getSize() > $file->getMaxFilesize()) {
         $this->context->buildViolation($constraint->messageMaxSize, array('%max_size%' => $file->getMaxFilesize()))->atPath('file')->addViolation();
     }
 }
开发者ID:open-orchestra,项目名称:open-orchestra-media-bundle,代码行数:15,代码来源:MediaFileValidator.php

示例10: determineFilesizeLimit

 /**
  * Determines if the file is too large
  * 
  * @throws Exception
  */
 private function determineFilesizeLimit()
 {
     $php_ini = ini_get('upload_max_filesize');
     $mb = str_replace('M', '', $php_ini);
     $bytes = $mb * 1048576;
     if ($this->file->getSize() > $bytes) {
         throw new \Exception('File too large');
     }
 }
开发者ID:ambarsetyawan,项目名称:Laravel5Starter,代码行数:14,代码来源:ICR.php

示例11: setupFile

 /**
  * Setup image file
  *
  * @param UploadedFile $file
  * @param string       $style_guide
  */
 public function setupFile(UploadedFile $file, $style_guide = null)
 {
     $this->_source = $file;
     $this->setFileExtension($file->getClientOriginalExtension());
     $this->setFileNameAttribute($file->getClientOriginalName());
     $this->setMimeTypeAttribute($file->getClientMimeType());
     $this->setFileSizeAttribute($file->getSize());
     if (!empty($style_guide)) {
         $this->setStyleGuideName($style_guide);
     }
 }
开发者ID:pablolovera,项目名称:attacher,代码行数:17,代码来源:AttacherModel.php

示例12: putUploadedFile

 /**
  * @param UploadedFile $uploadedFile
  * @param FileEntity   $fileEntity
  * @return bool
  */
 public function putUploadedFile(UploadedFile $uploadedFile, FileEntity $fileEntity)
 {
     list($path, $filesystem, $settings) = $this->getConfigValuesForRecordType($fileEntity->getRecordType());
     $fullPath = $path . DIRECTORY_SEPARATOR . $fileEntity->getFileName();
     $this->getFilesystem($filesystem)->putStream($fullPath, fopen($uploadedFile->getPathname(), 'r'), $settings);
     $fileEntity->setContentType($uploadedFile->getMimeType())->setSize($uploadedFile->getSize());
     /** @var EntityManager $em */
     $em = $this->container['orm.em'];
     $em->flush();
     return $fileEntity;
 }
开发者ID:apitude,项目名称:file,代码行数:16,代码来源:FileService.php

示例13: add

 /**
  * @param UploadedFile $file
  * @return Document
  */
 public function add(UploadedFile $file)
 {
     $document = new Document();
     $document->setExtension($file->guessExtension())->setMime($file->getMimeType())->setName($file->getClientOriginalName())->setSize($file->getSize());
     if (is_null($document->getExtension())) {
         $document->setExtension($file->getClientOriginalExtension());
     }
     $this->em->persist($document);
     $this->em->flush();
     $file->move($this->directory . '/' . substr($document->getId(), 0, 1), $document->getId() . '.' . $document->getExtension());
     return $document;
 }
开发者ID:thomasage,项目名称:asso,代码行数:16,代码来源:DocumentManager.php

示例14: getFile

 /**
  * @param string $email
  * @return UploadedFile
  * @throws InvalidArgumentException
  */
 public function getFile($email)
 {
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         throw new InvalidArgumentException();
     }
     $hash = md5(strtolower(trim($email)));
     $guzzle = new Client();
     $tempDirectory = sys_get_temp_dir();
     $guzzle->request("GET", "http://gravatar.com/avatar/" . $hash . "?d=404", [RequestOptions::SINK => $tempDirectory . '/' . $hash]);
     $file = new File($tempDirectory . '/' . $hash);
     $fileOriginalName = $hash . '.' . $file->guessExtension();
     $file = new UploadedFile($tempDirectory . '/' . $hash, $fileOriginalName, $file->getMimeType(), $file->getSize(), null, true);
     return $file;
 }
开发者ID:EnterprisePHP,项目名称:symfony-prime,代码行数:19,代码来源:Gravatar.php

示例15: createFromUploadedFile

 /**
  * @param FileInterface $storageFile
  * @param UploadedFile $uploadData
  */
 public function createFromUploadedFile(FileInterface $storageFile, UploadedFile $uploadData)
 {
     $fileSystem = new Filesystem();
     $storageFile->setFileName($uploadData->getClientOriginalName());
     $storageFile->setMimeType($uploadData->getMimeType());
     $storageFile->setSize($uploadData->getSize());
     if (!$storageFile->getId()) {
         $this->save($storageFile);
     } else {
         $fileSystem->remove($this->getFilePath($storageFile));
     }
     $storageFile->setStorageId(uniqid($storageFile->getId() . '_', false));
     $uploadData->move($this->getStorageDirectory($storageFile), $storageFile->getStorageId());
     $this->save($storageFile);
 }
开发者ID:beaast-com,项目名称:beaast-core,代码行数:19,代码来源:FileManager.php


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