Skip to content

Instantly share code, notes, and snippets.

@bernardoVale
Created March 10, 2013 18:43
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 bernardoVale/5129804 to your computer and use it in GitHub Desktop.
Save bernardoVale/5129804 to your computer and use it in GitHub Desktop.
Pagina que contem o fileUpload
<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>
<?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