Q:

Putting each item of a csv file line into a variable

I have the following code which I am using to open up an uploaded csv file, and then output each line on a separate line.
  if(isset($_GET['uploadfile'])) {
 $file = fopen($_FILES['csvfile']['tmp_name'], 'r+');
 while(! feof($file))
{
 echo fgets($file). "<br />";
 }
 fclose($file);
  }

The ouput looks like this :
        ABC,-,-,-,-,-,- 
        ACR,-,-,-,-,-,- 
        AGL,-,1.60,-,3.25,-,6.35 
        AGO,-,-,-,-,-,- 
        AHS,-,-,4.00,-,-,- 
        ALC,-,1.60,-,3.00,-,6.35 
        ALV,-,-,4.00,-,-,- 
        AMG,-,-,-,-,-,- 
        ANF,-,-,-,-,7.95,- 
        ANG,-,-,-,-,-,- 
        ANN,-,1.60,-,3.25,-,- 
        ANV,0.87,1.60,-,-,-,- 
        APO,-,-,-,-,-,- 
        ARP,-,-,-,-,-,- 
        ARR,-,1.60,-,3.00,-,6.35 
        ASH,-,-,-,-,-,- 
        ATG,-,-,-,-,-,- 
        ATR,-,1.60,-,3.00,-,- 
        AUE,-,1.60,-,3.25,-,- 
        AUN,-,1.60,-,3.25,-,- 
        AUR,-,-,-,-,-,- 
        BAB,0.87,1.60,-,-,-,- 
        BAL,-,1.60,-,-,-,6.35 
        BBE,-,-,-,-,-,- 
        BBL,-,-,-,-,-,- 
        BCH,-,1.60,-,3.25,-,- 
        BDI,-,-,-,-,-,- 
        BEM,-,-,-,-,7.95,- 
        BEN,-,-,-,-,-,- 
        BGE,-,-,-,3.25,-,- 
        BIA,-,-,-,-,-,- 
        BIF,-,1.60,-,3.25,-,- 
        BLC,0.87,1.60,-,3.25,-,- 

So there is a product code and then 5 csv cells, each spaced with a comma. What im trying to do is assign a variable to each as it runs, so
   BLC,0.87,1.60,-,3.25,-,- 

could become 
     $productcode.$value1.$value2.$value3.$value4.$value5

for each loop of the while loop. Im not sure how on earth to pull each line apart though, so id appreciate any pointers anyone has on how to do it.

A:

if(isset($_GET['uploadfile'])) {
    $file = fopen($_FILES['csvfile']['tmp_name'], 'r+');
    while(! feof($file))
    {
        $line = fgetcsv($file);

        list($productcode, $value1, $value2, $value3, $value4, $value5) = $line;

        // Ready to use the variables and insert to database
    }
    fclose($file);
}

Here you go, now  you can use the varibles as you want, and insert in the database after the list functions has been done, so at the comment i made.

