22 enero, 2011

Tutorial cargar o subir un archivo(imagen) en Php.


form1.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>
<body>
<form action="subir.php" method="post" enctype="multipart/form-data" id="form1">
  archivo 
  <label>
  <input name="archivo" type="file" id="archivo" />
  </label>
  <label>
  <input type="submit" name="Submit" value="Enviar" />
  </label>
</form>
</body>
</html>

subir.php
<?php 
$nombre_original = $_FILES["archivo"] ["name"] ;
$tipo = $_FILES["archivo"] ["type"] ;
$tam = $_FILES["archivo"] ["size"] ;
$temporal = $_FILES["archivo"] ["tmp_name"] ;
echo " nombre original : $nombre_original<br>";
echo " tipo de archivo : $tipo <br>";
echo " tama&ntilde;o en bytes : $tam <br>";
echo " archivo temporal : $temporal <br>";
if(($tipo=="image/jpeg")or ($tipo=="image/pjpeg") or ($tipo=="image/gif")){
copy ($temporal,"archivos/$nombre_original");
}else {
echo "solo se permiten im&aacute;genes";
}
?>

No hay comentarios:

Publicar un comentario

Grax.