本文整理匯總了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)]);
}
}
示例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);
}
示例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));
});
}