Foros del Web » Programando para Internet » PHP »

Ayuda con subida de img

Estas en el tema de Ayuda con subida de img en el foro de PHP en Foros del Web. alli estan los 3 archivos necesarios para subir una img, pero lo malo es que no sube la img y no se porque Código HTML: ...
  #1 (permalink)  
Antiguo 11/01/2010, 15:23
 
Fecha de Ingreso: marzo-2009
Mensajes: 356
Antigüedad: 15 años, 1 mes
Puntos: 7
Ayuda con subida de img

alli estan los 3 archivos necesarios para subir una img, pero lo malo es que no sube la img y no se porque

Código HTML:
<script>
function ver(image){
document.getElementById('image').innerHTML = "<img src='"+image+"'>" 
}
</script>
<form action="sube.php" method="post" enctype="multipart/form-data"> 
    Archivo: <input name="file" type="file"  onChange="ver(form.file.value)"> 
    <input name="submit" type="submit" value="Upload!">  
</form><br> <span id="image"></span>

Código HTML:
La imagen fue enviada con exito.<br><strong>Datos:</strong><br>
<ul>
  <li>Tipo <?=$tipo?></li>
  <li>Ubicacion http://xxx.xxx.xxx.xxx/<?=$destino . '/' .$cad.'.'.$tipo?></li>
</ul><br>
<img src="http://xxx.xxx.xxx.xxx/<?=$destino.'/'.$cad.'.'.$tipo?>"> 

Código PHP:
<? 
if($_POST){
// Creamos la cadena aletoria
$str "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
$cad "";
for(
$i=0;$i<12;$i++) {
$cad .= substr($str,rand(0,62),1);
}
// Fin de la creacion de la cadena aletoria
$tamano $_FILES 'file' ][ 'size' ]; // Leemos el tamaño del fichero
$tamaño_max="50000000000"// Tamaño maximo permitido
if( $tamano $tamaño_max){ // Comprovamos el tamaño 
$destino 'imagenes/Trabajadores' // Carpeta donde se guardata
$sep=explode('image/',$_FILES["file"]["type"]); // Separamos image/
$tipo=$sep[1]; // Optenemos el tipo de imagen que es
if($tipo == "gif" || $tipo == "pjpeg" || $tipo == "bmp"){ // Si el tipo de imagen a subir es el mismo de los permitidos, segimos. Puedes agregar mas tipos de imagen
move_uploaded_file $_FILES 'file' ][ 'tmp_name' ], $destino '/' .$cad.'.'.$tipo);  // Subimos el archivo
include('post.html'); // Incluimos la plantilla
}
else echo 
"el tipo de archivo no es de los permitidos";// Si no es el tipo permitido lo desimos
}
else echo 
"El archivo supera el peso permitido.";// Si supera el tamaño de permitido lo desimos
}
?>
  #2 (permalink)  
Antiguo 11/01/2010, 15:25
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Ayuda con subida de img

Te da algún mensaje de error o que es lo que ves?

Saludos.
  #3 (permalink)  
Antiguo 11/01/2010, 15:29
 
Fecha de Ingreso: marzo-2009
Mensajes: 356
Antigüedad: 15 años, 1 mes
Puntos: 7
Respuesta: Ayuda con subida de img

segun lo que entiendo, me debe mandar el mensaje de que se subio correctamente, pero solo se queda pantalla blanca sin nada; y no sube la img
  #4 (permalink)  
Antiguo 11/01/2010, 15:54
Avatar de blogger  
Fecha de Ingreso: diciembre-2005
Ubicación: frente al monitor
Mensajes: 398
Antigüedad: 18 años, 4 meses
Puntos: 12
Respuesta: Ayuda con subida de img

Aquí te adjunto este código, te sube una imagen y hasta te crea una thumbnail de la misma.

Código PHP:
<?php
 
 $idir 
$session->username."/images/";   // Path To Images Directory
 
$tdir $session->username."/images/thumbs/";   // Path To Thumbnails Directory
 
$twidth "125";   // Maximum Width For Thumbnail Images
 
$theight "100";   // Maximum Height For Thumbnail Images
  
 
if (!isset($_GET['subpage'])) {   // Image Upload Form Below   ?>
   <form method="post" action="uploader.php?subpage=upload" enctype="multipart/form-data">
    File:<br />
   <input type="file" name="imagefile" class="form">
   <br /><br />
   <input name="submit" type="submit" value="Sumbit" class="form">  <input type="reset" value="Clear" class="form">
   </form>
 <? } else  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script
   
$url $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use
   
if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {
     
$file_ext strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php
     
$copy copy($_FILES['imagefile']['tmp_name'], "$idir" $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location

     
if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location
       
print 'Image uploaded successfully.<br /><a href="'.$session->username.'/images/'.$url.'"><img src="'.$session->username.'/images/thumbs/'.$url.'"></a>';   // Was Able To Successfully Upload Image
       
$simg imagecreatefromjpeg("$idir" $url);   // Make A New Temporary Image To Create The Thumbanil From
       
$currwidth imagesx($simg);   // Current Image Width
       
$currheight imagesy($simg);   // Current Image Height
       
if ($currheight $currwidth) {   // If Height Is Greater Than Width
          
$zoom $twidth $currheight;   // Length Ratio For Width
          
$newheight $theight;   // Height Is Equal To Max Height
          
$newwidth $currwidth $zoom;   // Creates The New Width
       
} else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
         
$zoom $twidth $currwidth;   // Length Ratio For Height
         
$newwidth $twidth;   // Width Is Equal To Max Width
         
$newheight $currheight $zoom;   // Creates The New Height
       
}
       
$dimg imagecreate($newwidth$newheight);   // Make New Image For Thumbnail
       
imagetruecolortopalette($simgfalse256);   // Create New Color Pallete
       
$palsize ImageColorsTotal($simg);
       for (
$i 0$i $palsize$i++) {   // Counting Colors In The Image
        
$colors ImageColorsForIndex($simg$i);   // Number Of Colors Used
        
ImageColorAllocate($dimg$colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use
       
}
       
imagecopyresized($dimg$simg0000$newwidth$newheight$currwidth$currheight);   // Copy Resized Image To The New Image (So We Can Save It)
       
imagejpeg($dimg"$tdir" $url);   // Saving The Image
       
imagedestroy($simg);   // Destroying The Temporary Image
       
imagedestroy($dimg);   // Destroying The Other Temporary Image
       
print 'Image thumbnail created successfully.';   // Resize successful
     
} else {
       print 
'<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed
     
}
   } else {
     print 
'<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong
     
print $file_ext;   // Show The Invalid File's Extention
     
print '.</font>';
   }
 }

?>
Espero te sirva y le puedas sacar provecho.
__________________
http://exegesis-biblica.com/

Etiquetas: img, subida
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 22:08.