Ver Mensaje Individual
  #7 (permalink)  
Antiguo 19/07/2009, 22:16
Gabodium
 
Fecha de Ingreso: julio-2009
Mensajes: 12
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: Subir imagenes a host.

Pegué esto en el body:

Cita:
<form method="post" enctype="multipart/form-data" action="uploadphoto.php">
<input name="imagen" type="file">
</form>
Y esto en un archivo .php:


Cita:
<?php

if (preg_match("/jpg|jpeg/",$imagen_type))
{
$nombreimagen = "../pl_images/".$nombre.".jpg";
copy ($imagen, $nombreimagen) or die ("Imposible copiar el archivo");
crearthumb($nombreimagen,"../pl_thumbs/".$nombre.".jpg",200,160);
}

function crearthumb($nombre,$thnombre,$ancho,$alto)
{
global $gd2;
if (preg_match("/jpg|jpeg/",$nombre))
{ $src_img=imagecreatefromjpeg($nombre); }
if (preg_match("/png/",$nombre))
{ $src_img=imagecreatefrompng($nombre); }
$antiguo_x=imageSX($src_img);
$antiguo_y=imageSY($src_img);
if ($antiguo_x > $antiguo_y)
{
$thumb_w=$ancho;
$thumb_h=$antiguo_y*($alto/$antiguo_x);
}
if ($antiguo_x < $antiguo_y) {
$thumb_w=$antiguo_x*($ancho/$antiguo_y);
$thumb_h=$alto;
}
if ($antiguo_x == $antiguo_y) {
$thumb_w=$ancho;
$thumb_h=$alto;
}
if ($gd2==""){
$dst_img=ImageCreate($thumb_w,$thumb_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_ w,$thumb_h,$antiguo_x,$antiguo_y);
}else{
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thum b_w,$thumb_h,$antiguo_x,$antiguo_y);
}
if (preg_match("/png/",$system[1])){
imagepng($dst_img,$thnombre);
} else {
imagejpeg($dst_img,$thnombre);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}

?>