How to validate the headers of a csv uploaded with cck filefield? I need my users to upload a csv, using a cck filefield. I then wish to confirm they have the correct order of columns.

My research led me to believe that writing a custom validator for the filefield, was the best option. I have used this as a resource: https://drupal.org/node/546146 for writing it... 

I then used this for an example of how to open a csv and read it: http://oliverhuynh.wordpress.com/2011/06/21/drupal-batch-csv-importing-template/ ... 

I'm very new to this and lack the insights to spot what i'm doing wrong... Here's my code:

function MYMODULE_form_alter(&amp;$form, $form_state, $form_id) {
  if($form_id == 'stocklist_node_form') {     

    $form['field_stocklist'][0]['#upload_validators']['stocklist_validation'] = array();
    return $form;
  }

}

/**
 * The validation for the file.
 *
 */

function stocklist_validation($field) {
  // variable for error messages
  $errors = array();


  // do some processing on the field / file
  $filepath = $field-&gt;filepath;
  global $base_url;
  $fileurl = $base_url . '/' . $file_path;
 // Open the file
      if ( $handle = fopen($fileurl, 'r') ) {
        $line_count = 1 ;
        $first = TRUE ;
        if ( $line = fgetcsv($handle, 4096) ) {

        // Validate the headers 

         if ( $line[0] !== 'manufacturer' ) {
            $errors[] = t('Unable to verify uploaded file !filepath. Please ensure the file has the correct file type, column names and information.', array('!filepath' =&gt; $field-&gt;filename));
         }
        }
        fclose($handle);
      }


// in case of error, add error message

          return $errors;
}


I would really appreciate any help or pointers... I feel I'm one step away from finishing it but running out of google searches... It doesn't matter whether I upload a valid or invalid file, it just throws the defined error message... Why is it doing that?

edit: 

Here is a screenshot using devel whilst viewing a 'stocklist' type node. Thought it may help...
Just got this too work:

/**
 * The validation for the stocklist.
 *
 */

function stocklist_validation($field) {
  // variable for error messages
  $errors = array();

  // do some processing on the field / file
  $filepath = $field-&gt;filepath;

 // Open the file

      if ( $handle = fopen($filepath, 'r') ) {
        $line_count = 1 ;
        $first = TRUE ;
        if ( $line = fgetcsv($handle, 4096) ) {

        // Validate the headers 
         if ( $line[0] !== 'something' ) {
            $errors[] = t('Please ensure the files 1st column has the something in it. Including something as the heading.'); 
         }

    if ( $line[1] !== 'somethingelse' ) {
            $errors[] = t('Please ensure the files 2nd column has the somethingelse in it. Including somethingelse as the heading.'); 
         }


        fclose($handle);
      }

           else {
        $errors[] = t('Unable to open uploaded file !filepath.', array('!filepath' =&gt; $filepath));   
       }
      } 
// in case of errors, return error messages

          return $errors;
}


The first function didn't need changing... 

In the second function, it was the fopen() that needed changing. Secondly, like an idiot I just realised that the "valid" file was actually tab delimited... Doh! Would be nice to be able to accept those files too. As some software saves csv files in that format, such as the one I clearly used, OpenOffice.