0

Hi Im using REST API in yii 2 \yii\web\UploadedFile::getInstance is not getting file in my function.for debugging purpose I tried with $_FILES['asset'] its printing with values.but not getting file instance using \yii\web\UploadedFile::getInstance

$updateFile = $_FILES['asset']; //Printing values
$model->asset = \yii\web\UploadedFile::getInstance($model, 'asset'); //Not printing,its empty

What is the issues,I couldn't validate If i process the file with $_FILES.Any help would be grateful!! Thanks in Advance

Muhammad Shahzad
  • 9,340
  • 21
  • 86
  • 130
Jackhad
  • 411
  • 3
  • 8
  • 19

2 Answers2

1

Try this:

getInstanceByName('asset');
Vishva G
  • 399
  • 7
  • 25
  • Yep..its works!! but not validates ` $updateFile =UploadedFile::getInstanceByName( 'asset'); if($model->validate() && $updateFile) { $updateFile->saveAs(Yii::getAlias('@app') . '/web/uploads/'.$updateFile->name); $model->asset = $updateFile->name; }else{ $model->asset = $oldfile; }` – Jackhad Jun 11 '16 at 04:18
0

Your data should come like $_FILES['Your_Model_Name']['asset'] if you want to use UploadedFile::getInstance method. Try this, it will work.

$updateFile = $_FILES['User']['asset']; //Printing values
$model->asset = \yii\web\UploadedFile::getInstance($model, 'asset'); // Not printing, it's empty
arogachev
  • 33,150
  • 7
  • 114
  • 117