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