Hola buenas tardes alguien me podria ayudar con este error:
move_uploaded_file(uploads/Data.csv): failed to open stream: No such file or directory
quiero subir un archivo .CSV a mis tablas de yii2 avanced y me sale ese error agradeceria su gran ayuda.
este es mi codigo en el controlador:
public function actionUploadperiod(){
$model = new CsvForm;
if($model->load(Yii::$app->request->post())){
$file = UploadedFile::getInstance($model,'file');
$filename = 'Data.'.$file->extension;
$upload = $file->saveAs('uploads/'.$filename);
if($upload){
define('CSV_PATH','uploads/');
$csv_file = CSV_PATH . $filename;
$filecsv = file($csv_file);
print_r($filecsv);
foreach($filecsv as $data){
$modelnew = new Period;
$hasil = explode(",",$data);
$periodID = $hasil[0];
$periodName = $hasil[1];
$startDate = $hasil[2];
$endDate = $hasil[3];
$modelnew->periodID = $periodID;
$modelnew->periodName = $periodName;
$modelnew->startDate = $startDate;
$modelnew->endDate = $endDate;
$modelnew->save();
}
unlink('uploads/'.$filename);
return $this->redirect(['site/index']);
}
}else{
return $this->render('upload',['model'=>$model]);