Created
March 10, 2013 18:43
-
-
Save bernardoVale/5129804 to your computer and use it in GitHub Desktop.
Pagina que contem o fileUpload
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
<html> | |
<head> | |
<link rel="stylesheet" type="text/css" href="index.css"> | |
</head> | |
<body> | |
<form enctype="multipart/form-data" action="agenda.php" method="POST"> | |
<input type="hidden" name="MAX_FILE_SIZE" value="100000" /> | |
<div class="import"> | |
<label>Importar Arquivo</label> | |
<input type="file" id="import" name="import" value="Importar"/> | |
<input type="submit" id="saveImport" name="saveImport" value="Salvar"/> | |
<?php | |
include 'readXML.php'; | |
echo "<br/>"; | |
// Pasta fisica no projeto, onde ficará os arquivos | |
$target_path = "uploads/"; | |
/* Add the original filename to our target path. | |
Result is "uploads/filename.extension" */ | |
$target_path = $target_path . basename( $_FILES['import']['name']); | |
if(move_uploaded_file($_FILES['import']['tmp_name'], $target_path)) { | |
$arquivo = basename( $_FILES['import']['name']); | |
$xml = new readXML(); | |
$vetor = $xml->read($arquivo); | |
echo $vetor->getNome(); | |
} else{ | |
echo "Problemas ao tentar fazer upload do arquivo!"; | |
} | |
?> | |
</div> | |
</form> | |
</body> | |
</html> |
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
<?php | |
include 'AgendaBean.php'; | |
include 'AgendaList.php'; | |
class ReadXML{ | |
public function read($file){ | |
@header('Content-Type: text/html; charset=utf-8'); | |
$xml = simplexml_load_file("uploads/".$file); | |
return $this->parseObject($xml); | |
} | |
private function parse($xml){ | |
$cont = 0; | |
foreach($xml->contato as $contato){ | |
$vetor[$cont]['nome'] = $contato->nome; | |
$vetor[$cont]['email'] = $contato->ra; | |
$vetor[$cont]['telefone'] = $contato->faltas; | |
$vetor[$cont]['dtNascimento'] = $contato->faltas; | |
$cont += 1; | |
} | |
return $vetor; | |
} | |
private function parseObject($xml){ | |
$cont = 0; | |
foreach($xml->contato as $contato){ | |
$c = new AgendaBean(); | |
$c->setNome($contato->nome); | |
$c->setEmail($contato->email); | |
$c->setTelefone($contato->telefone); | |
$c->setDtNascimento($contato->dtNascimento); | |
$agendaList = new AgendaList(); | |
$agendaList->addContato($c); | |
} | |
$agendaList->viewAll(); | |
return $c; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment