Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. public function actionUploadLogo(){
  2. $uploaded = UploadedFile::getInstance(new UploadLogo(),'logo');
  3. return $uploaded //a quick check here is null
  4.  
  5. $uploaded->saveAs('uploads/settings/' . $uploaded->baseName
  6. . '.' . $uploaded->extension); //throws an error $uploaded is null
  7.  
  8. }
  9.  
  10. class UploadLogo extends Model
  11. {
  12. public $logo;
  13.  
  14. public function rules()
  15. {
  16. return [
  17. [['logo'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],
  18. ];
  19. }
  20.  
  21. public function upload()
  22. {
  23. if ($this->validate()) {
  24. $this->logo->saveAs('uploads/settings/' . $this->logo->baseName . '.' . $this->logo->extension);
  25. return true;
  26. } else {
  27. var_dump($this->getErrors());
  28. die();
  29. return false;
  30. }
  31. }
  32. }
  33.  
  34. Array
  35. (
  36. [logo] => Array
  37. (
  38. [name] => TWICE1.png
  39. [type] => image/png
  40. [tmp_name] => /tmp/phpj8dYFq
  41. [error] => 0
  42. [size] => 41646
  43. )
  44.  
  45. )
  46.  
  47. yiiwebUploadedFile Object
  48. (
  49. [name] => TWICE1.png
  50. [tempName] => /tmp/php2JqCMw
  51. [type] => image/png
  52. [size] => 41646
  53. [error] => 0
  54. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement