![lloron](http://static.forosdelweb.com/fdwtheme/images/smilies/chillando.png)
Código PHP:
<?php
define ("MAX_SIZE","10000");
define ("WIDTH","50");
define ("HEIGHT","37");
function make_thumb($img_name,$filename,$new_w,$new_h)
{
$ext=getExtension($img_name);
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);
if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if($ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if(!strcmp("png",$ext))
imagepng($dst_img,$filename);
else
imagejpeg($dst_img,$filename);
imagedestroy($dst_img);
imagedestroy($src_img);
}
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
if(isset($_POST['Submit']))
{
$image=$_FILES['image']['name'];
if ($image)
{
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "JPG") && ($extension != "JPEG") && ($extension != "PNG") && ($extension != "png"))
{
echo '<h1>Solo se pueden subir archivos .JPG .GIF o .PNG !!</h1>';
$errors=1;
}
else
{
$size=getimagesize($_FILES['image']['tmp_name']);
$sizekb=filesize($_FILES['image']['tmp_name']);
if ($sizekb > MAX_SIZE*10000)
{
echo '<h1>El tamaño de la foto es demaciado grande !!</h1>';
$errors=1;
}
$destinatario = $_POST["gleria"];
$image_name= $_POST["pgleri"];
$newname= "".$destinatario."/images/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>NO se pudo completar la copia !!</h1>';
$errors=1;
}
else
{
$thumb_name= "".$destinatario."/images/thumbs/".$image_name;
$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
}} }}
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>Miniatura creada con éxito !!</h1>";
echo '<img src="'.$thumb_name.'">';
}
?>
<!-- next comes the form, you must set the enctype to "multipart/form-data" and use an input type "file" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Subir Fotos</title>
<meta NAME="ROBOT" CONTENT="NOINDEX,NOFOLLOW">
<style>
h1 { font-family: Verdana ; font-size: 14pt; color: #FFFFFF}
th { font-family: Verdana ; font-size: 10pt; color: #FFFFFF}
tr { font-family: Verdana ; font-size: 10pt; color: #FFFFFF}
td { font-family: Verdana ; font-size: 10pt; color: #FFFFFF}
p { font-family: Verdana ; font-size: 10pt; color: #FFFFFF}
a { font-family: Verdana ; font-weight: bold; font-size: 10pt; color: #0000FF }
a:hover { color: #FF0000}
a{text-decoration:none}
BODY{
margin-top: 10px;
margin-left: 10px;
margin-right: 0px;
margin-bottom: 0px;
}
</style>
</head>
<body bgcolor="#000000">
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td>Buscar Archivo: <input type="file" name="image" ></td></tr>
<tr><td>Galería: <select name="gleria">
<option SELECTED VALUE="galeria1">Fotos Viaje 1</option>
<option VALUE="galeria2">Fotos Viaje 2</option>
<option VALUE="galeria3">Fotos Viaje 3</option>
<option VALUE="galeria4">Fotos Viaje 4</option>
</select> Foto N°: <select name="pgleri">
<option SELECTED VALUE="001.jpg">001</option>
<option VALUE="002.jpg">002</option>
<option VALUE="003.jpg">003</option>
<option VALUE="004.jpg">004</option>
<option VALUE="005.jpg">005</option>
</select></td></tr>
<tr><td><input name="Submit" type="submit" value="Subir"></td></tr>
</table>
</form>
</body>
<html>