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