Cuploadedfile Header

need to put in array the first line(header) of uploaded csv.

this is my code


$model= new ImportForm;

        if (isset($_POST['ImportForm'])) {

            $arr= array();

             

           $arr=  str_getcsv( fgets(CUploadedFile::getInstance($model,'csv')),0,';');

fgets() expects parameter 1 to be resource, object given

I need to compare the header to the atributeLabels of the model

and validate

You have to read entire file, so use file_get_contents instead fgets (that read a line at time).

Then pass "tempName" attribute to file_get_contents, that contains temporary path of file you have uplaoded.

Should be:




$model= new ImportForm;

        if (isset($_POST['ImportForm'])) {

            $arr= array();

             

           $arr=  str_getcsv( file_get_contents(CUploadedFile::getInstance($model,'csv')->tempName),0,';');



thanks.

but how to get the first line ?

Sorry, then for only the first line use fgets:




$handle = fopen(CUploadedFile::getInstance($model,'csv')->tempName, "r");

if ($handle) {

   $firstLine = fgets($handle, 4096);

   $arr=  str_getcsv( $firstLine,0,';');


   fclose($handle);

}