oop - Locate CSV file in different directory so it can be opened with php

85

I am writing a small app to upload csv files to a folder on a server, then those files will be opened and parsed. But, I'm having trouble pulling these uploaded csv files from their folder where I am saving them. It looks a little like:

 //$save_csv->filename is property that i want to open and read
 $csvPath = SITE_ROOT.DS.'csv_files'.DS.$save_csv->filename;

 public static function getdata($csvFile){
    $file_handle = fopen($csvFile, 'r');
    while (!feof($file_handle)) {
        fgetcsv($file_handle);
        $line_of_text[] = fgetcsv($file_handle);
    }
    fclose($file_handle);
    return $line_of_text;
} 
    $csv = parse_csv::getdata($csvPath);

     //This is where i parse the csv file for the info i want       
    foreach ($csv as $line){
            $callNum = $line[2];
            $author = $line[5];
            $title = $line[6];
            $oclcNum = $line[13];
            echo sprintf("Title: %s %s OCLC: %s", $title,$author,$oclcNum);
            echo "<br />";
    }

Theparse::getdata is a method that opens and reads the csv file, But again I can't figure out how to pull the file to be opened. Any help would be fantastic! Thanks!

People are also looking for solutions to the problem: PHP end a financial year in june of every year

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.