Esta es la función
Código PHP:
<?php
function img_resize($path,$w=0,$h=0,$quality=100,$save=''){
$image_data=@getimagesize($path);
$image_type=$image_data[2];
$gd_ext=array('','jpg','gif');
if($image_type!=1&&$image_type!=2) return false;
if($save=='') header('Content-type: '.$image_data['mime']); else $save=eregi_replace('%ext',$gd_ext[$image_type],$save);
if($w!=0){
$rapporto=$image_data[0]/$w;
if($h!=0){
if($image_data[1]/$rapporto>$h) $rapporto=$image_data[1]/$h;
}
}elseif($h!=0){
$tmp_h=$image_data[1]/$h;
}else{
return false;
}
$thumb_w=$image_data[0]/$rapporto;
$thumb_h=$image_data[1]/$rapporto;
if($image_type==1) $img_src=@imagecreatefromgif($path);
elseif($image_type==2) $img_src=@imagecreatefromjpeg($path);
$img_thumb=@imagecreatetruecolor($thumb_w,$thumb_h);
$result=@imagecopyresampled($img_thumb,$img_src,
0,0,0,0,$thumb_w,$thumb_h,$image_data[0],$image_data[1]);
if(!$img_src||!$img_thumb||!$result) return false;
if($image_type==1) $result=@imagegif($img_thumb,$save);
elseif($image_type==2) $result=@imagejpeg($img_thumb,$save,$quality);
return $result;
}
?>
Código PHP:
<? require ("../../includes/conn.php");
require ("../../includes/thumbs.php");
$data = "articulo_".date ("d-m-y-H-i-s");
if($foto_name !=""){
$strs = explode(".",$foto_name);
$count= count($strs);
$extension = ".".$strs[$count-1];
$fotonombre= $data.$extension;
$foto1= "../../fotos/".$data.$extension;
$var23 = getimagesize($foto);
if($var23[0] > 800) {
img_resize($foto ,$w=800,$h=0,$quality=100,$save=$foto1);
}else{
img_resize($foto ,$w=$var23[0],$h=$var23[1],$quality=100,$save=$foto1);
}
}
$data2 = "articulo_peque_".date ("d-m-y-H-i-s");
if($foto2_name !=""){
$strs = explode(".",$foto2_name);
$count= count($strs);
$extension = ".".$strs[$count-1];
$fotonombre2 = $data2.$extension;
$foto3 = "../../fotos/".$fotonombre2;
$var24 = getimagesize($foto2);
if($var24[1] > 73) {
img_resize($foto2 ,$w=0,$h=73,$quality=100,$save=$foto3);
}else{
img_resize($foto2 ,$w=$var24[0],$h=$var24[1],$quality=100,$save=$foto3);
}
}
$title = $nombre;
$SQL="INSERT INTO fichas VALUES ('', '$artista', '$seccion', '$title', '$anio', '$referencia', '$textfield', '$fotonombre2', '$fotonombre')";
mysql_query($SQL, $link);
if (mysql_errno($link)==0){
}else{
if (mysql_errno($link)==1062){echo "<h2>No ha podido añadirse el registro<br>Ya existe un campo</h2>";
}else{
$numerror=mysql_errno($link);
$descrerror=mysql_error($link);
echo "Se ha producido un error nº $numerror que corresponde a: $descrerror <br>";
}
}
mysql_close();
?>
<script>
alert ('Se ha añadido un nuevo articulo');
window.document.location.href="index.php";
</script>
La "foto" sube sin problemas, el problema es la "foto2" que si bien se guarda en la BD, no sube la imagen al servidor. Ya le di muchas vueltas y no consigo darme cuenta porque... Alguna idea?
Desde ya muchas gracias. Saludos