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


PHP UploadedFile::getExtension方法代码示例

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


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

示例1: moveUploadedFile

 public function moveUploadedFile(UploadedFile $file, $uploadBasePath, $relativePath)
 {
     $originalName = $file->getFilename() . '.' . $file->guessExtension();
     $targetFileName = $relativePath . DIRECTORY_SEPARATOR . $originalName;
     $targetFilePath = $uploadBasePath . DIRECTORY_SEPARATOR . $targetFileName;
     $ext = $file->getExtension();
     $i = 1;
     while (file_exists($targetFilePath) && md5_file($file->getPath()) != md5_file($targetFilePath)) {
         if ($ext) {
             $prev = $i == 1 ? "" : $i;
             $targetFilePath = $targetFilePath . str_replace($prev . $ext, $i++ . $ext, $targetFilePath);
         } else {
             $targetFilePath = $targetFilePath . $i++;
         }
     }
     $targetDir = 'uploads';
     if (!is_dir($targetDir)) {
         $ret = mkdir($targetDir, 777, true);
         if (!$ret) {
             throw new \RuntimeException("Could not create target directory to move temporary file into.");
         }
     }
     $file->move($targetDir, basename($targetFilePath));
     return str_replace($uploadBasePath . DIRECTORY_SEPARATOR, "", $targetFilePath);
 }
开发者ID:kevin-ta,项目名称:Form-wizard,代码行数:25,代码来源:UploadFileMover.php

示例2: moveUploadedFile

 public function moveUploadedFile(UploadedFile $file, $uploadBasePath, $relativePath, $fileName)
 {
     $originalName = $file->getFilename();
     // use filemtime() to have a more determenistic way to determine the subpath, otherwise its hard to test.
     // $relativePath = date('Y-m', filemtime($file->getPath()));
     $targetFileName = $relativePath . DIRECTORY_SEPARATOR . $originalName;
     $targetFilePath = $uploadBasePath . DIRECTORY_SEPARATOR . $targetFileName;
     $ext = $file->getExtension();
     $i = 1;
     while (file_exists($targetFilePath) && md5_file($file->getPath()) != md5_file($targetFilePath)) {
         if ($ext) {
             $prev = $i == 1 ? "" : $i;
             $targetFilePath = $targetFilePath . str_replace($prev . $ext, $i++ . $ext, $targetFilePath);
         } else {
             $targetFilePath = $targetFilePath . $i++;
         }
     }
     $targetDir = $uploadBasePath . DIRECTORY_SEPARATOR . $relativePath;
     if (!is_dir($targetDir)) {
         $ret = mkdir($targetDir, umask(), true);
         if (!$ret) {
             throw new \RuntimeException("Could not create target directory to move temporary file into.");
         }
     }
     //$file->move($targetDir, basename($targetFilePath));
     //$file->move($targetDir, basename($fileName.'.'.$ext));
     $file->move($targetDir, basename($fileName));
     return str_replace($uploadBasePath . DIRECTORY_SEPARATOR, "", $targetFilePath);
 }
开发者ID:alangalipaud,项目名称:ProjetQCM,代码行数:29,代码来源:UploadFileMover.php

示例3: uploadFile

 /**
  * Upload file
  *
  * @param null $fileName
  * @return bool|null|string
  * @throws AttachModelException
  */
 public function uploadFile($fileName = null)
 {
     if (!$this->totalFile instanceof UploadedFile) {
         return false;
     }
     if (!class_exists('Imagick')) {
         throw new AttachModelException('The requested PHP extension ext-imagick * is missing from your system.');
     }
     if (null === $fileName) {
         if (null === ($ext = $this->totalFile->guessExtension())) {
             $ext = $this->totalFile->getExtension();
         }
         $fileName = sha1(uniqid(mt_rand(), true));
         if (null !== $ext) {
             $fileName .= '.' . $ext;
         }
     } else {
         if ($this->totalFile->getClientOriginalExtension()) {
             $fileName .= '.' . $this->totalFile->getClientOriginalExtension();
         } elseif ($this->totalFile->getExtension()) {
             $fileName .= '.' . $this->totalFile->getExtension();
         }
     }
     $fullUploadPath = $this->getFullUploadPath();
     if (!is_dir($fullUploadPath)) {
         if (!mkdir($fullUploadPath, 0775, true)) {
             throw new AttachModelException('Not possible create UploadDirectory: ' . $fullUploadPath);
         }
     }
     $move = false;
     if ($this->widthHeight) {
         $move = $this->resize($fullUploadPath, $this->getOriginalPrefix() . $fileName, $this->widthHeight);
         if ($this->widthHeightPreview) {
             $this->resize($fullUploadPath, $this->getPreviewPrefix() . $fileName, $this->widthHeightPreview);
         }
     }
     if (!$move) {
         $source = new \Imagick($this->totalFile->getRealPath());
         $source->writeImage($fullUploadPath . DIRECTORY_SEPARATOR . $this->getOriginalPrefix() . $fileName);
     }
     return $fileName;
 }
开发者ID:zk2,项目名称:useful-bundle,代码行数:49,代码来源:AttachModelTrait.php

示例4: prepareUploadData

 /**
  * Returns an array of data for upload model
  *
  * @param UploadedFile $uploadedFile
  * @return array
  */
 protected function prepareUploadData(UploadedFile $uploadedFile)
 {
     return ['extension' => $uploadedFile->getExtension(), 'mimetype' => $uploadedFile->getMimeType(), 'size' => $uploadedFile->getSize(), 'name' => $uploadedFile->getBasename('.' . $uploadedFile->getExtension())];
 }
开发者ID:pb199486,项目名称:Transit,代码行数:10,代码来源:UploadService.php

示例5: testGetExtension

 public function testGetExtension()
 {
     $file = new UploadedFile(__DIR__ . '/Fixtures/test.gif', 'original.gif', null);
     $this->assertEquals('gif', $file->getExtension());
 }
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:5,代码来源:UploadedFileTest.php

示例6: prepareFileLocation

 /**
  * Prepares the file location name using the file dispersion feature.
  *
  * @param  \Symfony\Component\HttpFoundation\File\UploadedFile|string  $file
  * @param  string  $destination
  * @return string
  */
 public function prepareFileLocation($file, $destination = null)
 {
     $manager = $this->getManager();
     $placeholders = array_merge($manager->getPlaceholders(), [' ' => '_']);
     if ($file instanceof UploadedFile) {
         $placeholders = array_merge($placeholders, [':extension' => $file->getExtension(), ':mime' => $file->getMimeType()]);
     }
     $destination = $file instanceof UploadedFile ? $destination : $file;
     $destination = $manager->getDispersion() . $destination;
     return str_replace(array_keys($placeholders), array_values($placeholders), $destination);
 }
开发者ID:sohailaammarocs,项目名称:lfc,代码行数:18,代码来源:Filesystem.php

示例7:

 /**
  * @param UploadedFile $uploadedFile
  */
 function __construct($uploadedFile)
 {
     $path = sha1(uniqid(mt_rand(), true)) . '.' . $uploadedFile->getExtension();
     $this->setPath($path);
     $uploadedFile->move($this->getUploadRootDir(), $path);
 }
开发者ID:kolyatri,项目名称:justcoded_task,代码行数:9,代码来源:Image.php

示例8: upload

 public function upload(UploadedFile $file)
 {
     $fileName = $file->getBasename('.' . $file->getExtension()) . '.' . $file->guessExtension();
     $file->move($this->targetDir, $fileName);
     return $fileName;
 }
开发者ID:franiglesias,项目名称:milhojas,代码行数:6,代码来源:FileUploader.php

示例9: createThumb

 /**
  * Crea la miniatura de imagenes
  * @param UploadedFile $file 
  * @param string $path 
  * @return string Nombre del nuevo archivo
  */
 public function createThumb($file, $path)
 {
     $ext = $file->getExtension();
     $search = $this->config["images"]["images_ext"];
     if (array_search($ext, $search) !== false) {
         $fullpath = $this->getFullPath() . $path;
         $fullpaththumb = $this->getFullPath() . '/_thumbs' . $path;
         $filename = $file->getFilename();
         $filename_new = $this->removeExtension($filename) . '-' . $this->config['images']['resize']['thumbWidth'] . 'x' . $this->config['images']['resize']['thumbHeight'] . '.' . $file->getExtension();
         $fullpaththumb_name = $this->getFullPath() . '/_thumbs' . $path . $filename_new;
         if ($this->config['debug']) {
             $this->_log(__METHOD__ . " - {$fullpaththumb}");
         }
         $filethumb = new Filesystem();
         if ($filethumb->exists($fullpaththumb_name) == false) {
             if ($this->config['debug']) {
                 $this->_log(__METHOD__ . " - " . $fullpaththumb_name);
             }
             if ($filethumb->exists($fullpaththumb) == false) {
                 $filethumb->mkdir($fullpaththumb);
             }
             Imagen::open($fullpath . $file->getFilename())->zoomCrop($this->config['images']['resize']['thumbWidth'], $this->config['images']['resize']['thumbHeight'])->save($fullpaththumb_name);
         }
         return $filename_new;
     } else {
         if ($this->config['debug']) {
             $this->_log(__METHOD__ . " - {$ext}");
         }
     }
 }
开发者ID:guillermomartinez,项目名称:filemanager-php,代码行数:36,代码来源:Filemanager.php

示例10: getExifReadData

 /**
  * @param UploadedFile $fileObject
  * @return array
  */
 private function getExifReadData(UploadedFile $fileObject)
 {
     Log::debug($fileObject->getPath());
     Log::debug($fileObject->getFilename());
     Log::debug($fileObject->getBasename());
     Log::debug($fileObject->getClientMimeType());
     Log::debug($fileObject->getExtension());
     Log::debug($fileObject->getType());
     $result = [];
     $mimeType = $fileObject->getClientMimeType();
     // upload_igm and thumbnail directory make
     $dirName = date('Ym');
     $uploadDir = public_path() . '/upload_img/' . $dirName;
     $thumbnailDir = public_path() . '/thumbnail/' . $dirName;
     $this->chkDir($uploadDir);
     $this->chkDir($thumbnailDir);
     //@todo オリジナル動画をリサイズする
     $extension = explode('/', $fileObject->getClientMimeType())[1];
     $newFileName = sha1($fileObject->getFilename() . time()) . '.' . $extension;
     $saveFileName = $uploadDir . '/' . $newFileName;
     $fileObject->move($uploadDir, $newFileName);
     $thumbnail = Image::make(file_get_contents($saveFileName));
     $thumbnail->resize(100, null, function ($constraint) {
         $constraint->aspectRatio();
     });
     $thumbnail->save($thumbnailDir . '/' . $newFileName, 100);
     $result['file_name'] = $dirName . '/' . $newFileName;
     if ($mimeType !== 'image/jpeg') {
         return $result;
     }
     $exif = exif_read_data($saveFileName);
     if ($exif === false) {
         return false;
     }
     $result['file_date_time'] = isset($exif['DateTimeOriginal']) ? $exif['DateTimeOriginal'] : null;
     $result['file_size'] = $exif['FileSize'];
     $result['mime_type'] = $exif['MimeType'];
     $result['width'] = $exif['COMPUTED']['Width'];
     $result['height'] = $exif['COMPUTED']['Height'];
     $result['make'] = isset($exif['Make']) ? $exif['Make'] : null;
     $result['model'] = isset($exif['Model']) ? $exif['Model'] : null;
     $result['orientation'] = isset($exif['Orientation']) ? $exif['Orientation'] : null;
     if (isset($exif["GPSLatitude"])) {
         //緯度を60進数から10進数に変換
         $lat = $this->convert_float($exif["GPSLatitude"][0]) + $this->convert_float($exif["GPSLatitude"][1]) / 60 + $this->convert_float($exif["GPSLatitude"][2]) / 3600;
         //南緯の場合はマイナスにする
         if ($exif["GPSLatitudeRef"] == "S") {
             $lat *= -1;
         }
         //経度を60進数から10進数に変換
         $lng = $this->convert_float($exif["GPSLongitude"][0]) + $this->convert_float($exif["GPSLongitude"][1]) / 60 + $this->convert_float($exif["GPSLongitude"][2]) / 3600;
         //西経の場合はマイナスにする
         if ($exif["GPSLongitudeRef"] == "W") {
             $lng *= -1;
         }
         $result['lat'] = $lat;
         $result['lng'] = $lng;
     }
     return $result;
 }
开发者ID:picolit,项目名称:bbs,代码行数:64,代码来源:ArticleService.php


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