Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionUploadLogo(){
- $uploaded = UploadedFile::getInstance(new UploadLogo(),'logo');
- return $uploaded //a quick check here is null
- $uploaded->saveAs('uploads/settings/' . $uploaded->baseName
- . '.' . $uploaded->extension); //throws an error $uploaded is null
- }
- class UploadLogo extends Model
- {
- public $logo;
- public function rules()
- {
- return [
- [['logo'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],
- ];
- }
- public function upload()
- {
- if ($this->validate()) {
- $this->logo->saveAs('uploads/settings/' . $this->logo->baseName . '.' . $this->logo->extension);
- return true;
- } else {
- var_dump($this->getErrors());
- die();
- return false;
- }
- }
- }
- Array
- (
- [logo] => Array
- (
- [name] => TWICE1.png
- [type] => image/png
- [tmp_name] => /tmp/phpj8dYFq
- [error] => 0
- [size] => 41646
- )
- )
- yiiwebUploadedFile Object
- (
- [name] => TWICE1.png
- [tempName] => /tmp/php2JqCMw
- [type] => image/png
- [size] => 41646
- [error] => 0
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement