Skip to content

Instantly share code, notes, and snippets.

@smzn
Created May 3, 2017 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smzn/3d31473f8fda11dfe1ec2b39a3563574 to your computer and use it in GitHub Desktop.
Save smzn/3d31473f8fda11dfe1ec2b39a3563574 to your computer and use it in GitHub Desktop.
import
public function import(){
if($this->request->is('post')){
$up_file = $this->data['School']['XmlFile']['tmp_name'];
$fileName = 'post.xml';
if(is_uploaded_file($up_file)){
move_uploaded_file($up_file, $fileName);
$xmlArray = Xml::toArray(Xml::build($fileName));
$i = 0;
foreach($xmlArray['Dataset']['ksj:School'] as $line){
$latlng = explode(" ",$xmlArray['Dataset']['gml:Point'][$i++]['gml:pos']);
$data = array(
'name' => $line['ksj:name'],
'address' => $line['ksj:address'],
'region_id' => str_pad($line['ksj:administrativeArea']['@'],5,'0',STR_PAD_LEFT),
'category_id' => $line['ksj:type'],
'latitude' => $latlng[0],
'longitude' => $latlng[1]
);
$this->School->create($data);
$this->School->save();
}
}
}
$this->redirect(array('action'=>'index'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment