Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/12/2011, 23:51
Avatar de Asus2800
Asus2800
 
Fecha de Ingreso: mayo-2011
Mensajes: 39
Antigüedad: 13 años
Puntos: 1
Pregunta Necesito hacer un cambio en un upload que tengo funcionando.

Buenas estimados amigos de forosdelweb, dado que mi conocimiento en php es muy poco pero estoy aprendiendo de a poco, necesito en este uploader que sube una imagen y genera su Thumbnail, que las 2 imagenes se guarden en la misma carpeta pero que a los Thumbnail le cambie el prefijo del nombre image_0 por thumb_0, osea que cambie solo image o thumb y mantenga el _(nº) q tenga.

Resumiendo, una imagen llamada "image_0" la subo y quiero que me quede en la misma carpeta , image_0 y thumb_0.

Este codigo me funciona bien, si algun novato como yo quiere usarlo para hacer un uploader. Pero preciso esa modificacion y despues de mil intentos eh recurrido a ustedes para no molestarlos antes. Saludos gente y espero esa ayudita.

Código PHP:
<?

// Below lines are to display file name, temp name and file type , you can use them for testing your script only//////
echo "<center>File Name: ".$_FILES[userfile][name]."</center><br>";
/*echo "tmp name: ".$_FILES[userfile][tmp_name]."<br>";
echo "File Type: ".$_FILES[userfile][type]."<br>";*/
echo "<br><br>";
if (!(
$_FILES[userfile][type] =="image/jpeg" OR $_FILES[userfile][type]=="image/gif")){echo "<center>Formato no soportado, Vuelva atras eh intente con una Imagen .Jpg o .Gif</center><BR>";
exit;}
///////////////////////////////////////////////////////////////////////////
$add="upimg/".$_FILES[userfile][name]; // the path with the file name where the file will be stored, upload is the directory name. 
//echo $add;
if(move_uploaded_file ($_FILES[userfile][tmp_name],$add)){
echo 
"<center>Imagen subida con exito</center>";
chmod("$add",0777);

}else{echo 
"Failed to upload file Contact Site admin to fix the problem";
exit;}

///////// Start the thumbnail generation//////////////
$n_width=180;          // Fix the width of the thumb nail images
$n_height=240;         // Fix the height of the thumb nail imaage

$tsrc="thimg/".$_FILES[userfile][name];   // Path where thumb nail image will be stored.

//echo $tsrc;
if (!($_FILES[userfile][type] =="image/jpeg" OR $_FILES[userfile][type]=="image/gif")){echo "Formato no soportado, Intente con una Imagen .Jpg o .Gif<BR>";
exit;}
/////////////////////////////////////////////// Starting of GIF thumb nail creation///////////
if (@$_FILES[userfile][type]=="image/gif")
{
$im=ImageCreateFromGIF($add);
$width=ImageSx($im);              // Original picture width is stored
$height=ImageSy($im);                  // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
if (
function_exists("imagegif")) {
Header("Content-type: image/gif");
ImageGIF($newimage,$tsrc);
}
elseif (
function_exists("imagejpeg")) {
Header("Content-type: image/jpeg");
ImageJPEG($newimage,$tsrc);
}
chmod("$tsrc",0777);
}
////////// end of gif file thumb nail creation//////////

////////////// starting of JPG thumb nail creation//////////
if($_FILES[userfile][type]=="image/jpeg"){
$im=ImageCreateFromJPEG($add); 
$width=ImageSx($im);              // Original picture width is stored
$height=ImageSy($im); 
            
// Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);  
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc);
chmod("$tsrc",0777);
}
////////////////  End of JPG thumb nail creation //////////
?>
__________________
****EN LA PRACTICA Y EL ERROR NACE LA PERFECCION****