Skip to content

Instantly share code, notes, and snippets.

@fmagrosoto
Created February 27, 2014 22:12
Show Gist options
  • Save fmagrosoto/9260740 to your computer and use it in GitHub Desktop.
Save fmagrosoto/9260740 to your computer and use it in GitHub Desktop.
PHP para saber el tipo MIME de los archivos que subes a través de formularios.
<?php
$info = FALSE;
$submit = filter_input(INPUT_POST, 'submit');
if(isset($submit)){
$tamano = $_FILES["archivo"]['size'];
$tipo = $_FILES["archivo"]['type'];
$nombre = $_FILES["archivo"]['name'];
$temporal = $_FILES["archivo"]['tmp_name'];
$info = TRUE;
}
?>
<!DOCTYPE html>
<html lang="es-MX">
<head>
<meta charset="UTF-8" />
<title>MIME para archivos</title>
<style>
body {
background: whitesmoke;
color: rgb(51,51,51);
font-family: Georiga, serif;
font-size: 100%;
width: 50em;
margin: 3.125em auto;
}
h1 {
text-shadow: 1px 1px 1px white;
border-bottom: 1px gray dotted;
text-align: center;
}
form fieldset {
border: 1px gray solid;
border-radius: .5em;
padding: 0.625em;
}
form fieldset div {
margin-bottom: .5em;
}
form fieldset div:last-child {
margin-bottom: 0;
}
form fieldset legend {
border: 1px gray solid;
border-radius: .5em;
padding: 0.625em;
background: white;
}
table tr th {
width: 6.25em;
text-align: right;
padding: 0.3125em;
border: 1px lightgray solid;
background: white;
}
table tr td {
padding: 0.3125em;
border: 1px lightgray solid;
background: white;
}
footer {
margin-top: 50px;
font-size: 0.875em;
color: rgb(75,75,75);
border-top: 1px lightgray solid;
padding-top: 15px;
}
footer p {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<h1>INFORMACIÓN MIME PARA ARCHIVOS</h1>
<form action="mime.php" method="POST" enctype="multipart/form-data">
<fieldset>
<legend>Cargar archivo</legend>
<div>
<input type="file" name="archivo" />
</div>
<div>
<button type="submit" name="submit">Subir archivo</button>
</div>
</fieldset>
</form>
<?php if($info) { ?>
<div style="margin-top: 50px">
<table>
<tr>
<th>Nombre:</th>
<td><?php echo $nombre; ?></td>
</tr>
<tr>
<th>Temporal:</th>
<td><?php echo $temporal; ?></td>
</tr>
<tr>
<th>Tamaño:</th>
<td><?php echo $tamano; ?></td>
</tr>
<tr>
<th>Tipo:</th>
<td><?php echo $tipo; ?></td>
</tr>
</table>
</div>
<?php } ?>
<footer>
<p>&copy;2014 - Fernando Magrosoto</p>
<p>Sígueme en <a href="http://www.twitter.com/fmagrosoto">Twitter</a></p>
</footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment