Foros del Web » Programando para Internet » PHP »

renombrar imagen al subir

Estas en el tema de renombrar imagen al subir en el foro de PHP en Foros del Web. Tengo este codigo para subir multiples imagenes, funciona muy bien, pero no renombra el archivo al subir Código PHP: <?php /** * Smart Image Uploader by @cafewebmaster.com * Free for private use * Please support us with donations or backlinks */ ...
  #1 (permalink)  
Antiguo 15/01/2010, 08:06
Avatar de blogger  
Fecha de Ingreso: diciembre-2005
Ubicación: frente al monitor
Mensajes: 398
Antigüedad: 18 años, 4 meses
Puntos: 12
renombrar imagen al subir

Tengo este codigo para subir multiples imagenes, funciona muy bien, pero no renombra el archivo al subir

Código PHP:
<?php

/**
* Smart Image Uploader by @cafewebmaster.com
* Free for private use
* Please support us with donations or backlinks
*/


$upload_image_limit 5// How many images you want to upload at once?
$upload_dir            "./images/"// default script location, use relative or absolute path
$enable_thumbnails    // set 0 to disable thumbnail creation

##################### THUMBNAIL CREATER FROM GIF / JPG / PNG
    
function make_thumbnails($updir$img){

    
$thumbnail_width    125;
    
$thumbnail_height    100;
    
$thumb_preword        "thumb_";

    
$arr_image_details    GetImageSize("$updir"."$img");
    
$original_width        $arr_image_details[0];
    
$original_height    $arr_image_details[1];

    if( 
$original_width $original_height ){
        
$new_width    $thumbnail_width;
        
$new_height    intval($original_height*$new_width/$original_width);
    } else {
        
$new_height    $thumbnail_height;
        
$new_width    intval($original_width*$new_height/$original_height);
    }

    
$dest_x intval(($thumbnail_width $new_width) / 2);
    
$dest_y intval(($thumbnail_height $new_height) / 2);



    if(
$arr_image_details[2]==1) { $imgt "ImageGIF"$imgcreatefrom "ImageCreateFromGIF";  }
    if(
$arr_image_details[2]==2) { $imgt "ImageJPEG"$imgcreatefrom "ImageCreateFromJPEG";  }
    if(
$arr_image_details[2]==3) { $imgt "ImagePNG"$imgcreatefrom "ImageCreateFromPNG";  }


    if( 
$imgt ) { 
        
$old_image    $imgcreatefrom("$updir"."$img");
        
$new_image    imagecreatetruecolor($thumbnail_width$thumbnail_height);
        
imageCopyResized($new_image,$old_image,$dest_x,         
        
$dest_y,0,0,$new_width,$new_height,$original_width,$original_height);
        
$imgt($new_image,"$updir"."$thumb_preword"."$img");
    }

}









################################# UPLOAD IMAGES
    
        
foreach($_FILES as $k => $v){ 

            
$img_type "";

            
### $htmo .= "$k => $v<hr />";     ### print_r($_FILES);

            
if( !$_FILES[$k]['error'] && preg_match("#^image/#i"$_FILES[$k]['type']) && $_FILES[$k]['size'] < 1000000){

                
$img_type = ($_FILES[$k]['type'] == "image/jpeg") ? ".jpg" $img_type ;
                
$img_type = ($_FILES[$k]['type'] == "image/gif") ? ".gif" $img_type ;
                
$img_type = ($_FILES[$k]['type'] == "image/png") ? ".png" $img_type ;

                
$img_rname $_FILES[$k]['name'];
                
$img_path $upload_dir.$img_rname;

                
copy$_FILES[$k]['tmp_name'], $img_path ); 
                if(
$enable_thumbnailsmake_thumbnails($upload_dir$img_rname);
                
$feedback .= "Image and thumbnail created <a href=./images/$img_rname><img src=./images/thumb_$img_rname></a><br />";

            }
        }






############################### HTML FORM
    
while($i++ < $upload_image_limit){
        
$form_img .= '<label>Image '.$i.': </label> <input type="file" name="uplimg'.$i.'"><br />';
    }

    
$htmo .= '
        <p>'
.$feedback.'</p>
        <form method="post" enctype="multipart/form-data">
            '
.$form_img.' <br />
            <input type="submit" value="Upload Images!" style="margin-left: 50px;" />
        </form>
        '
;    

    echo 
$htmo;

?>
¿Alguien me puede ayudar a editarlo para que se renombren las imágenes al subirlas al servidor?
__________________
http://exegesis-biblica.com/
  #2 (permalink)  
Antiguo 15/01/2010, 08:57
Avatar de maturano  
Fecha de Ingreso: enero-2010
Ubicación: /home/
Mensajes: 537
Antigüedad: 14 años, 4 meses
Puntos: 36
Respuesta: renombrar imagen al subir

Estás usando copy() para colocar el archivo en su ubicación final. Eso es obsoleto y poco recomendable. Como sea, es ahí donde simplemente podrás colocarle el nombre que quieras.

www.php.net/copy
  #3 (permalink)  
Antiguo 15/01/2010, 08:58
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: renombrar imagen al subir

Si te fijas, en estas líneas asignas el nombre de la imagen:
Código PHP:
Ver original
  1. $img_rname = $_FILES[$k]['name'];
  2. $img_path = $upload_dir.$img_rname;
  3. copy( $_FILES[$k]['tmp_name'], $img_path );
Edítalas como prefieras el nombre de archivo.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #4 (permalink)  
Antiguo 15/01/2010, 17:05
(Desactivado)
 
Fecha de Ingreso: abril-2008
Mensajes: 787
Antigüedad: 16 años
Puntos: 7
Respuesta: renombrar imagen al subir

tambien puedes utilizar la funcion rename().

ya eso depende de ti.

saludos.

Última edición por esaenz22; 15/01/2010 a las 17:05 Razón: correccion.

Etiquetas: renombrar, subir
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:18.