本文整理汇总了PHP中UploadedFile::saveAs方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::saveAs方法的具体用法?PHP UploadedFile::saveAs怎么用?PHP UploadedFile::saveAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::saveAs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
public function upload()
{
if ($this->validate()) {
if (isset($this->avatarFile)) {
if (!is_dir(Yii::$app->params['uploadPath'] . '/avatar')) {
mkdir(Yii::$app->params['uploadPath'] . '/avatar', 0777, true);
}
$this->avatarFile->saveAs(Yii::$app->params['uploadPath'] . '/avatar/' . $this->avatarFile->baseName . '.' . $this->avatarFile->extension);
$this->avatar = '/avatar/' . $this->avatarFile->baseName . '.' . $this->avatarFile->extension;
$this->save(false);
}
return true;
} else {
return false;
}
}
示例2: upload
public function upload()
{
$this->setScenario('upload');
if ($this->validate()) {
$patch = Yii::getAlias('@uploads/' . $this->dirName);
if (!is_dir($patch)) {
mkdir($patch);
}
$fileName = 'sl_' . Yii::$app->security->generateRandomString(8) . '.' . $this->imageFile->extension;
if ($this->imageFile->saveAs($patch . '/' . $fileName)) {
$this->removeImage();
}
$this->image = $fileName;
return true;
}
return false;
}
示例3: saveUploadedFile
/**
* Save the uploaded file to filesystem path and optional resize before save it.
*/
protected function saveUploadedFile()
{
$uniqueId = uniqid(mt_rand(100, 1000));
$newName = $this->mediaFile->baseName . '_' . $uniqueId . '.' . $this->mediaFile->extension;
$webroot = Yii::getAlias('@webroot');
$dir = $webroot . DIRECTORY_SEPARATOR . $this->targetUrl;
FileHelper::createDirectory($dir);
$path = $dir . DIRECTORY_SEPARATOR . $newName;
$this->name = $this->mediaFile->name;
$this->url = $this->targetUrl . '/' . $newName;
$this->type = $this->mediaFile->type;
// resize the file (Check is done by [[addMediaRules]]
if (is_array($this->resize)) {
list($width, $height) = $this->resize;
$image = \kmergen\media\helpers\Image::thumb($this->mediaFile->tempName, $width, $height)->save($path);
$this->size = filesize($path);
} else {
$this->size = $this->mediaFile->size;
$this->mediaFile->saveAs($path);
}
}