Skip to content

Instantly share code, notes, and snippets.

@patrickcurl
Created January 31, 2014 17:16
Show Gist options
  • Save patrickcurl/8736939 to your computer and use it in GitHub Desktop.
Save patrickcurl/8736939 to your computer and use it in GitHub Desktop.
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