當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UploadedFile::className方法代碼示例

本文整理匯總了PHP中yii\web\UploadedFile::className方法的典型用法代碼示例。如果您正苦於以下問題:PHP UploadedFile::className方法的具體用法?PHP UploadedFile::className怎麽用?PHP UploadedFile::className使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\web\UploadedFile的用法示例。


在下文中一共展示了UploadedFile::className方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: create

 /**
  * @param $file string|\yii\web\UploadedFile
  * @return object
  * @throws InvalidConfigException
  */
 public static function create($file)
 {
     if (is_a($file, self::className())) {
         return $file;
     }
     // UploadedFile
     if (is_a($file, UploadedFile::className())) {
         if ($file->error) {
             throw new InvalidParamException("File upload error \"{$file->error}\"");
         }
         return \Yii::createObject(['class' => self::className(), 'path' => $file->tempName, 'extension' => $file->getExtension()]);
     } else {
         return \Yii::createObject(['class' => self::className(), 'path' => FileHelper::normalizePath($file)]);
     }
 }
開發者ID:yiioverflow,項目名稱:yii2-file-kit,代碼行數:20,代碼來源:File.php

示例2: populateFromUploadedFile

 /**
  * Populates the file with data from UploadedFile.
  * Sets the file status as [[self::STATUS_UPLOADED_FILE]] too.
  * @param UploadedFile $uploadedFile
  * @throws InvalidParamException if incorrect `$uploadedFile` was passed.
  */
 public function populateFromUploadedFile($uploadedFile)
 {
     if (!$uploadedFile instanceof UploadedFile) {
         throw new InvalidParamException('An instance of ' . UploadedFile::className() . ' is required in ' . __METHOD__ . '.');
     }
     $properties = ['name' => $uploadedFile->name, 'tempName' => $uploadedFile->tempName, 'type' => $uploadedFile->type, 'size' => $uploadedFile->size, 'error' => $uploadedFile->error];
     $this->resetCalculatedProperties();
     Yii::configure($this, $properties);
     $this->status = self::STATUS_UPLOADED_FILE;
     $this->setData(null, false);
 }
開發者ID:alex-dwt,項目名稱:file,代碼行數:17,代碼來源:File.php

示例3: testSaveUpload

 public function testSaveUpload()
 {
     $this->specify('test saveUpload', function () {
         $upload = Stub::make(UploadedFile::className(), ['name' => 'test.txt', 'saveAs' => Stub::once(function ($absoluteFilePath) {
             file_put_contents($absoluteFilePath, 'test content');
             return true;
         })], $this);
         $filePath = Yii::$app->uploads->saveUpload('test', $upload);
         $this->assertNotEmpty($filePath);
         $absoluteFilePath = Yii::$app->uploads->getAbsolutePath($filePath);
         $this->assertFileExists($absoluteFilePath);
         $this->assertEquals('test.txt', pathinfo($filePath, PATHINFO_BASENAME));
         $this->assertEquals('test content', file_get_contents($absoluteFilePath));
     });
 }
開發者ID:herroffizier,項目名稱:yii2-upload-manager,代碼行數:15,代碼來源:UploadManagerTest.php


注:本文中的yii\web\UploadedFile::className方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。