作者:amarchenko
项目:myCM
public function afterSave($insert, $changedAttributes)
{
$this->preview_input = UploadedFile::getInstance($this, 'preview_input');
if (!empty($this->preview_input)) {
$this->preview_input->saveAs($this->preview_picture);
}
parent::afterSave($insert, $changedAttributes);
}
作者:d3yii
项目:d3file
/**
* copy Yii2 UploadedFile
* @param UploadedFile $upoadFile
* @return boolean
* @throws NotFoundHttpException
*/
public function uploadYii2UloadFile(UploadedFile $upoadFile)
{
if (!$upoadFile->saveAs($this->getFilePath())) {
throw new NotFoundHttpException(Yii::t('d3files', 'The uploaded file does not exist.'));
}
return true;
}
作者:hanterria
项目:yii2-file-processor-modul
/**
* @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;
}
作者:bdar
项目:yii2-aws-s
/**
* Saves a file
* @param \yii\web\UploadedFile $file the file uploaded
* @param string $name the name of the file. If empty, it will be set to the name of the uploaded file
* @param array $options to save the file. The options can be any of the following:
* - `folder` : whether we should create a subfolder where to save the file
* @return boolean
*/
public function save($file, $name, $options = [])
{
$folder = ArrayHelper::getValue($options, 'folder');
$path = $folder ? $this->getBasePath() . DIRECTORY_SEPARATOR . $folder . ltrim($name, DIRECTORY_SEPARATOR) : $this->getBasePath() . DIRECTORY_SEPARATOR . ltrim($name, DIRECTORY_SEPARATOR);
@mkdir(dirname($path), 0777, true);
return $file->saveAs($path);
}
作者:dkhlysto
项目:yii2-uploadimag
/**
* Saving file to temporary directory and resize it if needed.
* @param UploadedFile $file File needs to save.
* @param integer $maxImageWidth Maximum image width.
* @param integer $maxImageHeight Maximum image height.
* @param integer $quality Image quality (for jpeg only).
* @return string Name of file relative to web root.
*/
public static function save(UploadedFile $file, $maxImageWidth, $maxImageHeight, $quality)
{
$name = self::generateName($file->name);
$filename = Yii::getAlias('@webroot') . $name;
$file->saveAs($filename);
$image = new ImageFile($filename, ['jpegQuality' => $quality]);
$image->bounds($maxImageWidth, $maxImageHeight);
$image->save();
return $name;
}
作者:kotmonst
项目:kotmonst
/**
* @inherited
*/
public function beforeSave($insert)
{
if ($this->file && $this->file instanceof UploadedFile && parent::beforeSave($insert)) {
FileHelper::createDirectory(dirname($this->filename));
return $this->file->saveAs($this->filename, false);
}
return false;
}
作者:thedollarsig
项目:easyi
public static function uploadLogo(UploadedFile $fileInstance, $dir = '', $resizeWidth = null, $resizeHeight = null, $resizeCrop = false)
{
$fileName = Upload::getUploadPath($dir) . DIRECTORY_SEPARATOR . 'logo.' . $fileInstance->extension;
$uploaded = $resizeWidth ? self::copyResizedImage($fileInstance->tempName, $fileName, $resizeWidth, $resizeHeight, $resizeCrop) : $fileInstance->saveAs($fileName);
if (!$uploaded) {
throw new HttpException(500, 'Cannot upload file "' . $fileName . '". Please check write permissions.');
}
return Upload::getLink($fileName);
}
作者:mops1
项目:yiimin
/**
* @param UploadedFile $file
*/
public function saveFile(UploadedFile $file)
{
if ($file) {
$folder = \Yii::getAlias('@webroot') . '/uploads/settings/' . $this->key . '/';
if (is_dir($folder) == false) {
mkdir($folder, 0755, true);
}
$file->saveAs($folder . $file->name);
Image::thumbnail($folder . $file->name, 160, 90)->save($folder . 'thumb_' . $file->name, ['quality' => 90]);
}
}
作者:Everu
项目:rgk_tes
public function upload()
{
if ($this->imageFile = UploadedFile::getInstance($this, 'imageFile')) {
$this->preview = md5($this->imageFile->baseName . time()) . '.' . $this->imageFile->extension;
$this->imageFile->saveAs(Yii::getAlias('@webroot') . '/' . self::UPLOAD_DIR . $this->preview);
$this->imageFile = NULL;
Image::thumbnail('@webroot/' . self::UPLOAD_DIR . $this->preview, 120, 120)->save(Yii::getAlias('@webroot') . '/' . self::UPLOAD_DIR . 'thumb/' . $this->preview, ['quality' => 80]);
}
}
作者:karse
项目:yii2-image-uploa
public function store(UploadedFile $file)
{
$storePath = \Yii::getAlias('@app/data');
if ($file->saveAs($storePath . '/' . $file->name, true)) {
$this->fileAttributes['store'] = 'data/' . $file->name;
$this->fileAttributes['url'] = \Yii::$app->urlManager->hostInfo . '/' . $this->fileAttributes['store'];
return true;
}
return false;
}
作者:hiqde
项目:hipanel-cor
/**
* 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;
}
作者:joorloohui
项目:bat-web-fronten
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;
}
作者:Polymedi
项目:BI-Platform-v
public function upload()
{
if ($this->validate()) {
$this->excelFile->saveAs(Yii::$app->basePath . '/uploads/' . $this->excelFile->baseName . '.' . $this->excelFile->extension);
return true;
} else {
return false;
}
}
作者:adem-tea
项目:advance
public function upload()
{
if ($this->validate()) {
$this->IMAGE->saveAs('upload/' . $this->IMAGE->baseName . '.' . $this->IMAGE->extension);
return true;
} else {
return false;
}
}
作者:RStuffGi
项目:mebe
public function uploadImage()
{
if ($this->validate() && $this->imageFile) {
$this->imageFile->saveAs(Yii::getAlias("@webroot") . '/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
return true;
} else {
return false;
}
}
作者:omniligh
项目:yii2-model
public function afterSave($insert, $changedAttributes)
{
if ($this->scenario == self::SCENARIO_FILE_UPLOAD) {
$fileName = $this->getFileName();
FileHelper::createDirectory(dirname($fileName));
$this->fileUpload->saveAs($fileName);
}
parent::afterSave($insert, $changedAttributes);
}
作者:eugenrei
项目:koio
public function upload()
{
if ($this->validate()) {
$this->filename = \Yii::$app->security->generateRandomString() . '.' . $this->file->extension;
$this->file->saveAs("uploads/{$this->filename}");
return true;
}
return false;
}
作者:bishabosh
项目:flai
public function upload()
{
if ($this->validate()) {
$this->imageFile->saveAs('img/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
return true;
} else {
return false;
}
}
作者:billccchen
项目:Yii2-Basi
public function upload()
{
if ($this->validate()) {
//yii::setAlias('@path1', 'localhost/basic/');
$this->imageFile->saveAs(\Yii::$app->basePath . '/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
return true;
} else {
return false;
}
}
作者:havenno
项目:sageone_tes
public function upload()
{
$file_path = \Yii::getAlias('@upload');
if ($this->validate()) {
$this->file->saveAs($file_path . $this->file->baseName . '.' . $this->file->extension);
return true;
} else {
return false;
}
}