Skip to content

Instantly share code, notes, and snippets.

@labra
Created October 18, 2016 18:48
Show Gist options
  • Save labra/d8b3fa364fc0b499a3c071110510b8fa to your computer and use it in GitHub Desktop.
Save labra/d8b3fa364fc0b499a3c071110510b8fa to your computer and use it in GitHub Desktop.
<html><head><title>Formulario</title></head>
<body>
<h1>Procesa ficheros</h1>
<?php if ($_SERVER['REQUEST_METHOD'] == 'GET') : ?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>"
method="POST"
enctype="multipart/form-data">
<label>Nombre:
<input name="cliente"></label><br>
<label>Dame un fichero:
<input name="fichero" type="file"></label><br>
<button>Enviar</button>
</form>
<?php
elseif ($_SERVER['REQUEST_METHOD'] == 'POST') :
echo "<h1>Hola {$_POST['cliente']}</h1>";
$nombre = $_FILES["fichero"]["name"];
echo "<p>Nombre de fichero: " . $nombre;
echo "<p>Nombre de fichero temporal: " . $_FILES["fichero"]["tmp_name"];
$str = file_get_contents($_FILES["fichero"]["tmp_name"]);
// echo "<p>Contenidos: <pre>" . $str . "</pre>" ;
$json = json_decode($str,true);
echo "<p>Guardando información de curso: " . $json["id"] ;
file_put_contents("listados/" . $nombre, json_encode($json));
else:
die("Sólo se admiten peticiones GET y POST.");
endif ?>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment