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