i m uploading csv file one row is uploading but more than one row is cannot uploaded
public function actionUploadcsv()
{
$model=new Studentmarks;
$filelist=CUploadedFile::getInstancesByName('name');
foreach($filelist as $file)
{
try{
$transaction = Yii::app()->db->beginTransaction();
ini_set("auto_detect_line_endings", true);
//if(($handle = fopen("$file->tempName", "r")) !== FALSE){
$handle = fopen("$file->tempName", "r");
$row = 1;
$temp = 0;
$notupdate = 0;
$newmodel=new Studentmarks;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if($data[0] != ""){
if($row>1){
date_default_timezone_set("Asia/Kolkata");
$timestamp = date('Y-m-d H:i:s');
$SchoolId=Yii::app()->session['Schoolid'];
$temp = 0;
$examtype = $data[0];
$classname = $data[1];
$subjectname =$data[2];
$coursename = $data[3];
$username = $data[4];
$modelp = Puserprofile::model()->findByAttributes(array('studentname'=>$username, 'Status'=>1,'puser_for'=>1, 'School_Id'=>$SchoolId));
$modele = Examtype::model()->findByAttributes(array('ExamName'=>$examtype, 'Status'=>1, 'School_Id'=>$SchoolId));
$modelc = Classdetails::model()->findByAttributes(array('classname'=>$classname, 'Status'=>1, 'School_Id'=>$SchoolId));
$models = Subject::model()->findByAttributes(array('SubjectName'=>$subjectname, 'Status'=>1, 'School_Id'=>$SchoolId));
if(!is_null($modelp) && !is_null($modele) && !is_null($modelc) && !is_null($models)){
if($coursename!="0"){
$modelsc = Subjectcourse::model()->findByAttributes(array('CourseName'=>$coursename, 'Status'=>1, 'School_Id'=>$SchoolId, 'SubjectId'=>$models->Subjectid));
if(!is_null($modelsc)){
$newmodel->pid = $modelp->pid;
$newmodel->ExamId = $modele->ExamId;
$newmodel->ClassId = $modelc->classid;
$newmodel->Subjectid = $models->Subjectid;
$newmodel->CourseId = $modelsc->CourseId;
$newmodel->Mark = $data[5];
$newmodel->Timestamp=$timestamp;
$newmodel->School_Id=$SchoolId;
$newmodel->Status=1;
if($newmodel->save()){
$count=$temp + 1;
$temp = $count;
}else{
$total = $notupdate + 1;
$notupdate = $total;
}
}
}else{
$newmodel->pid = $modelp->pid;
$newmodel->ExamId = $modele->ExamId;
$newmodel->ClassId = $modelc->classid;
$newmodel->Subjectid = $models->Subjectid;
$newmodel->Mark = $data[5];
$newmodel->Timestamp=$timestamp;
$newmodel->School_Id=$SchoolId;
$newmodel->Status=1;
if($newmodel->save()){
$count=$temp + 1;
$temp = $count;
}else{
$total = $notupdate + 1;
$notupdate = $total;
}
}
}
}
$row++;
// $transaction->commit();
}
else{
Yii::app()->user->setFlash('success', "CSV file should not be empty");
$this->refresh();
}
}
if($newmodel->save())
{
$transaction->commit();
Yii::app()->user->setFlash('success', $temp." Rows Success ".$notupdate." Unsuccess");
$this->refresh();
}else{
Yii::app()->user->setFlash('success', "CSV file upload not completed");
}
}catch(Exception $error){
print_r($error);
//print_r($classdet);
$transaction->rollback();
}
}
$this->render('uploadcsv',array(
'model'=>$model,
));
}