0

How should I get image from canvas to CUploadedFile::getInstance? or is there any way how to save image from canvas in Yii?

I have this:

  var canvas=document.getElementById("photoCanvas");
  photoData=canvas.toDataURL();

and I am using Ajax to get photoData to php, I aslo know how to save it onve it's loaded in CUploadedFile::getInstance

  $uploadedFile->saveAs(Yii::app()->basePath.'/../images/'.$fileName);

but what should be between these two codes? how should I save $_POST['photoData'] to $uploadedFile?

Simplified: How to get url image to CUploadedFile?

Riko
  • 433
  • 1
  • 6
  • 20

1 Answers1

0

It is not using $_FILES as would with classic file upload, if you have that data in $_POST['photoData'] simply use file_put_contents (decode first, see footnote):

file_put_contents(Yii::app()->basePath.'/../images/'.$fileName, $_POST['photoData']);

For decoding see PHP Data-URI to file

Community
  • 1
  • 1