0

Am uploading a file via ajax following this link This link ive been able to pass the files via ajax but am getting another error when moving the files

I dont want to provide an absolute path in my code like since different codes are used in different areas of the application so i prefer to use the getalis to return the actual path

This is what i have

move_uploaded_file($file_tmp, Yii::getAlias("@uploads/siteimages/slider/").$filename);

This is the filename

$file_ext = pathinfo($_FILES['TblSlider']['name']["file"], PATHINFO_EXTENSION);
 $filename = strtotime(date("Y-m-d h:m:s")).".".$file_ext;

Previously i tried using the getUploadedinstance but since its an ajax request it fails

By doing

var_dump($_FILES["TblSlider"]["tmp_name"])  It returns the actual tmp file

The path exisit where i wrong

Community
  • 1
  • 1
Geoff
  • 6,277
  • 23
  • 87
  • 197

1 Answers1

0

//Set the path that the file will be uploaded to

$path = Yii::getAlias('@frontend') .'/web/uploads/'

 move_uploaded_file($file_tmp, Yii::getAlias("@uploads/siteimages/slider/").$filename);

Try by changing Alias path like this

   Yii::getAlias('@frontend') .'/web/uploads/'

Help Url : How to upload files in web folder in yii2 advanced template?

Community
  • 1
  • 1
vijay nathji
  • 1,608
  • 13
  • 23