Q:

Php Yii2 upload base64 image fails with file_put_contents

Am receiving a base64 encoded image from android and i would like to upload it in yii2
SO i have added the following
$success = file_put_contents(Yii::getAlias('@web').'/uploads/img.png'
              ,base64_decode($detail));

WHere $detail is the base 64 encoded image
When i try uploading am getting an error 
yii\base\ErrorException: file_put_contents(/uploads/img.png):
  failed to open stream: No such file or directory 

What else do i need to add to make the upload work as most results show the above

A:

The problem is in alias you've used. The @web alias is the base URL of currently running application which is in your case an empty string. Thanks to that you are trying to save uploaded file as /uploads/img.png.
You've probably wanted to use @webroot alias instead. It points to the directory that contains index.php file.
You can find more about predefined aliases here. 

