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


PHP UploadedFile::getExtension方法代码示例

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


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

示例1: saveData

 /**
  * @param \yii\web\UploadedFile $file
  *
  * @return int
  */
 public function saveData(\yii\web\UploadedFile $file)
 {
     $ext = $file->getExtension();
     $baseName = $file->getBaseName();
     $model = new \metalguardian\fileProcessor\models\File();
     $model->extension = $ext;
     $model->base_name = $baseName;
     $model->save(false);
     return $model->id;
 }
开发者ID:hanterrian,项目名称:yii2-file-processor-module,代码行数:15,代码来源:FileTransfer.php

示例2: uploadFromPost

 /**
  *
  * @param UploadedFile $uploadedFile
  */
 public function uploadFromPost($uploadedFile)
 {
     if ($uploadedFile === null) {
         return;
     }
     $this->name = ltrim(pathinfo(' ' . $uploadedFile->name, PATHINFO_FILENAME));
     $this->extension = $uploadedFile->getExtension();
     $this->size = $uploadedFile->size;
     $this->type = $uploadedFile->type;
     $this->hash = $this->getHashName();
     $this->uploadFile($uploadedFile->tempName, $this->hash . "." . $this->extension);
     return $this;
 }
开发者ID:rocketyang,项目名称:hasscms-app,代码行数:17,代码来源:Attachment.php

示例3: beforeValidate

 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     if (!parent::beforeValidate()) {
         return false;
     }
     if ($this->image) {
         $content = file_get_contents($this->image->tempName);
         $extension = $this->image->getExtension();
         if (!($preview = Yii::$app->preview->save($content, $extension))) {
             return false;
         }
         $this->preview = $preview;
     }
     return true;
 }
开发者ID:MaxHero,项目名称:yii2-books,代码行数:18,代码来源:BookEdit.php

示例4: getNewFileName

 public function getNewFileName()
 {
     if (!$this->_newFileName) {
         $this->_newFileName = Yii::$app->security->generateRandomString() . '.' . $this->_uploadFile->getExtension();
     }
     return $this->_newFileName;
 }
开发者ID:Penton,项目名称:MoBlog,代码行数:7,代码来源:Upload.php

示例5: getSaveFileName

 private function getSaveFileName()
 {
     if (is_callable($this->format) || is_array($this->format)) {
         return call_user_func($this->format, $this);
     }
     //替换日期事件
     $t = time();
     $d = explode('-', date("Y-y-m-d-H-i-s"));
     $format = $this->format;
     $format = str_replace("{yyyy}", $d[0], $format);
     $format = str_replace("{yy}", $d[1], $format);
     $format = str_replace("{mm}", $d[2], $format);
     $format = str_replace("{dd}", $d[3], $format);
     $format = str_replace("{hh}", $d[4], $format);
     $format = str_replace("{ii}", $d[5], $format);
     $format = str_replace("{ss}", $d[6], $format);
     $format = str_replace("{time}", $t, $format);
     $srcName = mb_substr($this->uploadFileInstance->name, 0, mb_strpos($this->uploadFileInstance->name, '.'));
     $srcName = preg_replace("/[\\|\\?\"\\<\\>\\/\\*\\\\]+/", '', $srcName);
     $format = str_replace("{filename}", $srcName, $format);
     //替换随机字符串
     $randNum = rand(1, 10000000000) . rand(1, 10000000000);
     $matches = [];
     if (preg_match("/\\{rand\\:([\\d]*)\\}/i", $format, $matches)) {
         $randNumLength = substr($randNum, 0, $matches[1]);
         $format = preg_replace("/\\{rand\\:[\\d]*\\}/i", $randNumLength, $format);
     }
     $ext = $this->uploadFileInstance->getExtension();
     return $format . '.' . $ext;
 }
开发者ID:fatjiong,项目名称:yii2-webuploader,代码行数:30,代码来源:UploadAction.php

示例6: save

 /**
  * Сохранение файла на сервере
  */
 public function save()
 {
     // Если это действительно экземпляр объекта файла
     if ($this->file instanceof UploadedFile) {
         if (!FileHelper::createDirectory($this->_path)) {
             throw new InvalidParamException("Directory specified in '{$this->_path}' attribute doesn't exist or cannot be created.");
         }
         $name = FileHelper::getRandomFileName($this->_path, $this->file->getExtension());
         $filePath = $this->_path . DIRECTORY_SEPARATOR . $name;
         // Если оригинальная картинка сохранилась
         if ($this->file->saveAs($filePath)) {
             $imageInfo = getimagesize($filePath);
             list($width, $height) = $imageInfo;
             $this->_width = $width;
             $this->_height = $height;
             $this->_name = $name;
             /** @var ImagePathMap $imagePathMap */
             $imagePathMap = Yii::$app->get('imagePathMap', false);
             if ($imagePathMap != null) {
                 $imagePathMap->add($this->_name, $this->_pathID);
             }
             return true;
         }
     }
     return false;
 }
开发者ID:beowulfenator,项目名称:yii2-dynamic-image,代码行数:29,代码来源:ImageUploadForm.php

示例7: saveUploadedFile

 /**
  * Saves uploaded file under the [[tempDirectory]] with random file name
  *
  * @param UploadedFile $file
  * @return string randomly generated file name
  * @throws ErrorException when file is not saved
  */
 public function saveUploadedFile(UploadedFile $file)
 {
     do {
         $filename = Yii::$app->security->generateRandomString(16) . '.' . $file->getExtension();
         $path = $this->getTemporaryPath($filename);
     } while (is_file($path));
     if (!$file->saveAs($path)) {
         throw new ErrorException('Failed to save uploaded file');
     }
     return $filename;
 }
开发者ID:hiqdev,项目名称:hipanel-core,代码行数:18,代码来源:FileStorage.php

示例8: createFromUploadedFile

 public static function createFromUploadedFile(UploadedFile $file)
 {
     $upload = new static();
     $upload->mimetype = FileHelper::getMimeType($file->tempName);
     $upload->checksum = hash_file('sha256', $file->tempName);
     $upload->filename = $file->getBaseName() . '.' . $file->getExtension();
     $upload->filesize = $file->size;
     $upload->createContainerDir();
     $file->SaveAs($upload->getContainerDir() . '/' . $upload->filename);
     $upload->save();
     return $upload;
 }
开发者ID:joorloohuis,项目名称:bat-web-frontend,代码行数:12,代码来源:Upload.php

示例9: uploadPhoto

 /**
  * Загрузка изображения.
  *
  * @param UploadedFile $uploadedFile
  * @param $userId
  * @return bool
  */
 public function uploadPhoto(UploadedFile $uploadedFile, $userId)
 {
     if ($uploadedFile->getBaseName() && !$uploadedFile->getHasError()) {
         $photoName = 'profile_photo_' . $userId . '.' . $uploadedFile->getExtension();
         $photoSaveFolder = \Yii::getAlias('@app') . $this->profilePhotoFolder . '/' . $userId;
         if (!file_exists($photoSaveFolder)) {
             mkdir($photoSaveFolder);
         }
         $photoPath = $photoSaveFolder . '/' . $photoName;
         $uploadedFile->saveAs($photoPath);
         return $photoName;
     }
     return false;
 }
开发者ID:vlamug,项目名称:landing-page-crm,代码行数:21,代码来源:PhotoManagerComponent.php

示例10: afterValidate

 /**
  * After validation event
  */
 public function afterValidate()
 {
     //Save file to temp.
     //Save only new files
     //And if file does not have errors after validation
     if ($this->saveTemp && $this->file instanceof UploadedFile && !$this->file instanceof FakeUploadedFile && !$this->owner->hasErrors($this->attribute)) {
         $fileName = $this->tempPrefix . mt_rand() . '.' . $this->file->getExtension();
         $path = $this->generateFilePathInternal($fileName);
         FileHelper::createDirectory(dirname($path));
         if (copy($this->file->tempName, $path)) {
             $this->_tempFile = $path;
             $this->owner->{$this->attribute} = $this->generateFileUrlInternal($fileName);
             Yii::getLogger()->log('Save temparary file to ' . $path, Logger::LEVEL_INFO);
         }
     }
 }
开发者ID:maddoger,项目名称:yii2-filebehavior,代码行数:19,代码来源:FileBehavior.php

示例11: runForFile

 /**
  * @param UploadedFile $uploadedFile
  *
  * @return bool|string
  */
 public function runForFile(UploadedFile $uploadedFile)
 {
     $extension = $uploadedFile->getExtension();
     $baseName = $uploadedFile->getBaseName();
     if ($this->useMd5Names) {
         $filename = sprintf('%s', md5(time() . $baseName));
     } elseif (is_null($this->customName) == false) {
         $filename = sprintf("%s", $this->customName);
     } else {
         $filename = sprintf("%s", $baseName);
     }
     $filename = $this->getUniqueFilename($filename, $extension);
     $filePath = $this->getFilePath($filename);
     if ($uploadedFile->saveAs($filePath)) {
         return $filename;
     }
     return false;
 }
开发者ID:pbabilas,项目名称:bcode,代码行数:23,代码来源:Uploader.php

示例12: saveUploaded

 protected function saveUploaded(UploadedFile $file)
 {
     $dir = $this->getPath(false, true);
     $file_name = $file->getBaseName();
     $file_ext = $file->getExtension();
     $filename = $file_name . '.' . $file_ext;
     $index = 0;
     while (file_exists($dir . $filename)) {
         $index++;
         $filename = $file_name . '-' . $index . '.' . $file_ext;
     }
     FileHelper::createDirectory($dir, 0777, true);
     $path = $dir . $filename;
     if ($file->saveAs($path)) {
         return [$filename, filesize($path)];
     }
     return false;
 }
开发者ID:vsguts,项目名称:crm,代码行数:18,代码来源:Attachment.php

示例13: setNew

 /**
  * Sets a new logo image by given temp file
  *
  * @param CUploadedFile $file
  */
 public function setNew(UploadedFile $file)
 {
     $this->delete();
     move_uploaded_file($file->tempName, $this->getPath());
     ImageConverter::Resize($this->getPath(), $this->getPath(), array('height' => $this->height, 'width' => 0, 'mode' => 'max', 'transparent' => $file->getExtension() == 'png' && ImageConverter::checkTransparent($this->getPath())));
 }
开发者ID:kreativmind,项目名称:humhub,代码行数:11,代码来源:LogoImage.php

示例14: uploadByUploadFile

 /**
  * upload by UploadedFile instance.
  *
  * @param UploadedFile $uploadedFile Uploaded file instance
  * @param string $dir uploading file directory.
  * @param string $savePath upload file save path. If null, call [[getSavePath()]] to generate one.
  * @return File
  */
 public function uploadByUploadFile($uploadedFile, $dir, $savePath = null)
 {
     $file = new File();
     if ($uploadedFile === null) {
         $file->error = File::UPLOAD_ERROR_NO_UPLOADED_FILE;
         return $file;
     }
     // 检查上传文件是否有错
     if ($uploadedFile->getHasError()) {
         $file->error = $uploadedFile->error;
         return $file;
     }
     if ($savePath !== null) {
         $dir = $this->getDir($savePath);
     }
     $type = $uploadedFile->getExtension();
     $file->error = $this->getErrors($uploadedFile->size, $dir, $type);
     if ($file->error !== UPLOAD_ERR_OK) {
         return $file;
     }
     if ($savePath === null) {
         $savePath = $this->getSavePath($dir, $type);
     }
     if ($uploadedFile->saveAs($savePath)) {
         $file->url = $this->savePath2Url($savePath);
     } else {
         $file->error = File::UPLOAD_ERROR_UPLOAD;
     }
     return $file;
 }
开发者ID:wenbin1989,项目名称:yii2-upload,代码行数:38,代码来源:Uploader.php

示例15: getFileName

 /**
  * @param UploadedFile $file
  * @param callable $formatFileName
  * @return string
  */
 protected function getFileName(UploadedFile $file, \Closure $formatFileName = null)
 {
     $filename = $file->name;
     if (!is_null($formatFileName)) {
         $filename = call_user_func($formatFileName, $file->getBaseName(), $file->getExtension());
     }
     return $filename;
 }
开发者ID:opus-online,项目名称:yii2-file,代码行数:13,代码来源:UploadHandler.php


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