Created
January 31, 2014 17:16
-
-
Save patrickcurl/8736939 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App::uses('CsvFileObject', 'Lib'); | |
App::uses('CsvIterator', 'Lib'); | |
//... | |
public function upload() { | |
$file = $this->data['Book']['file']; | |
if ($file['error'] === UPLOAD_ERR_OK) { | |
if (move_uploaded_file($file['tmp_name'], APP.'webroot/uploads'.DS.$file['name'])) { | |
$path = APP.'webroot/uploads'.DS.$file['name']; | |
$file = new CsvFileObject($path); | |
$csv = new CsvIterator($file); | |
for($csv->rewind(); $csv->valid();$csv->next()){ | |
ClassRegistry::init('Book')->saveAll($csv->current()); | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment