Professional CodeIgniter, Thomas Myer

Chapter 7: Improving the Dashboard
199
Figure 7-6

The next part is where you start using the CSVReader library. You ' re going to add an
importCsv()

function to the MProducts model. In this function, you ' re going to load two libraries: upload and
CSVReader. You ' re going to upload the CSV files into the /tmp directory and use the
parseFile()

method to parse the document and return an array of data.
function importCsv(){
$config[`upload_path'] = `/tmp/';
$config[`allowed_types'] = `csv';
$config[`max_size'] = `2000';
$config[`remove_spaces'] = true;
$config[`overwrite'] = true;
$this-
>
load-
>
library(`upload', $config);
$this-
>
load-
>
library(`CSVreader');
if(!$this-
>
upload-
>
do_upload(`csvfile')){
$this-
>
upload-
>
display_errors();
exit();
}
$csv = $this-
>
upload-
>
data();
$path = $csv[`full_path'];
return $this-
>
csvreader-
>
parseFile($path);
}
c07.indd 199
c07.indd 199
6/10/08 5:36:42 PM
6/10/08 5:36:42 PM


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.

OK

Loading...
...
Закрыть