Foros del Web » Programando para Internet » PHP »

Subir Imagen a fichero

Estas en el tema de Subir Imagen a fichero en el foro de PHP en Foros del Web. Hola de nuevo, tengo el siguiente código: Código HTML: <tr height= "25" > <td> SUBIR FOTOGRAF &Iacute; AS </td> <td> <input type= "file" name= "uploadImage" ...
  #1 (permalink)  
Antiguo 17/02/2012, 00:48
 
Fecha de Ingreso: enero-2012
Mensajes: 52
Antigüedad: 12 años, 2 meses
Puntos: 1
Pregunta Subir Imagen a fichero

Hola de nuevo, tengo el siguiente código:
Código HTML:
<tr height="25">
 <td>SUBIR FOTOGRAF&Iacute;AS </td>
  <td>
  <input type="file" name="uploadImage" id="uploadImage" action="ficheros.php"/>
  <input type="submit" value="SUBIR" />	
  </td>
 </tr> 
con él, intento subir una imagen a un archivo que previamente he creado tomando el nombre desde un campo de un formulario.
Código PHP:
if ($_REQUEST["boton"]=="SUBIR"){
            
$vehiculo=new VpDAOClass();
            
$vehiculo->load($_REQUEST["matricula"]);
            if(!empty(
$_POST)){
      
var_dump(upload_image($_REQUEST["matricula"],'uploadImage'));
            }
        } 
Mi función es:
Código PHP:
function upload_image($destination_dir,$name_media_field){
        
$tmp_name $_FILES[$name_media_field]['tmp_name'];
        
//si hemos enviado un directorio que existe realmente y hemos subido el archivo    
        
if ( is_dir($destination_dir) && is_uploaded_file($tmp_name)){
            
$img_file  $_FILES[$name_media_field]['name'] ;
            
$img_type  $_FILES[$name_media_field]['type'];
            echo 
1;
            
//¿es una imágen realmente?           
            
if (((strpos($img_type"gif") || strpos($img_type"jpeg") || strpos($img_type,"jpg")) || strpos($img_type,"png") )){
                
//¿Tenemos permisos para subir la imágen?
                
echo 2;
                if(
move_uploaded_file($tmp_name$destination_dir.'/'.$img_file)){
                    return 
true;
                }
            }
        }
        
//si llegamos hasta aquí es que algo ha fallado
        
return false;
    }
//end function 
Mi problema es que no sube la imagen a la carpeta en cuestión.
¿Podéis decirme, por favor, dónde tengo el error?. Gracias. Saludos.
  #2 (permalink)  
Antiguo 17/02/2012, 01:01
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Subir Imagen a fichero

intento subir una imagen a un archivo que previamente he creado??
En cualquier caso comprueba que la carpeta exista, que el archivo tiene el tamaño permitido, que tienes los permisos adecuados, etc, etc... también puedes mirar los mil post que se han publicado ayer y hoy sobre este tema con los mismos problemas.
Saludos
__________________
Fere libenter homines, id quod volunt, credunt.
  #3 (permalink)  
Antiguo 17/02/2012, 01:18
 
Fecha de Ingreso: enero-2012
Mensajes: 52
Antigüedad: 12 años, 2 meses
Puntos: 1
Pregunta Respuesta: Subir Imagen a fichero

Cita:
Iniciado por repara2 Ver Mensaje
intento subir una imagen a un archivo que previamente he creado??
En cualquier caso comprueba que la carpeta exista, que el archivo tiene el tamaño permitido, que tienes los permisos adecuados, etc, etc... también puedes mirar los mil post que se han publicado ayer y hoy sobre este tema con los mismos problemas.
Saludos
La carpeta existe, el archivo tiene tamaño, extensión y permisos adecuados pero no consigo que suba. Gracias por el comentario pero llevo toda la semana mirando no mil sino, diez mil post al respecto y ninguno me ha solucinado el problema. En fin, espero que alguien pueda ayudarme. Gracias.
  #4 (permalink)  
Antiguo 17/02/2012, 02:57
 
Fecha de Ingreso: abril-2003
Ubicación: Mexico
Mensajes: 604
Antigüedad: 21 años
Puntos: 23
Información Respuesta: Subir Imagen a fichero

buenas

no pusiste todo el formulario peroa ni ne dio laqta algo muy simple...
te pongo la linea de envio del form
Código PHP:
<form action="sube.php" method="post" enctype="multipart/form-data"
y en donde recibes pones...
Código PHP:
$transfoto=$_FILES['userfile']; 
espero que te sirva

saludos
__________________
¡El Respeto al Derecho Ajeno Es la Paz!
  #5 (permalink)  
Antiguo 17/02/2012, 04:39
 
Fecha de Ingreso: enero-2012
Mensajes: 52
Antigüedad: 12 años, 2 meses
Puntos: 1
Respuesta: Subir Imagen a fichero

Cita:
Iniciado por HalconVigia Ver Mensaje
buenas

no pusiste todo el formulario peroa ni ne dio laqta algo muy simple...
te pongo la linea de envio del form
Código PHP:
<form action="sube.php" method="post" enctype="multipart/form-data"
y en donde recibes pones...
Código PHP:
$transfoto=$_FILES['userfile']; 
espero que te sirva

saludos
Aquí tienes todo el formulario:
Código HTML:
<h3>FOMULARIO DE MANTENIMIENTO DE VEH&Iacute;CULOS</h3>
<form  name="mantenimiento" action="mantenimientoCode.php" enctype="text/plain">
 <table border="0" style="left:45px;">
  <tr height="25">
   <td>MARCA </td>
   <td> 
 <input type="text" name="marca"  id="marca" size="18" maxlength="18" value="<?php echo $vehiculo->marca ?>">
   </td>
 </tr>
 <tr height="25">
  <td>MODELO </td>
  <td>
<input type="text" name="modelo" id="modelo" size="48" maxlength="28" value="<?php echo $vehiculo->modelo ?>">
  </td>
 </tr>
 <tr height="25">
  <td>TIPO DE VEH&Iacute;CULO </td>
  <td> 
   <select name="tipo_vehiculo" id="tipo_vehiculo">
     <option selected="turismo">TURISMO 
     <option value="deportivo">DEPORTIVO 
     <option value="4X4">4X4 
     <option value="furgoneta">FURGONETA 
     <option value="otro">OTRO 
     </select>
  </td>
 </tr>
 <tr height="25">
  <td>MATR&Iacute;CULA </td>
  <td>
<input type="text" name="matricula" id="matricula" size="12" maxlength="12" value="<?php echo $vehiculo->matricula ?>">
  </td>
 </tr>
 <tr height="25">
  <td>A&Ntilde;O DE MATRICULACI&Oacute;N </td>
  <td>
 <input type="text" name="anyo_matricula" id="anyo_matricula" size="4" maxlength="4" value="<?php echo $vehiculo->fecha_mat ?>">
 &nbsp; &nbsp;
 	KIL&Oacute;METROS
    <input type="text" name="kilometros" id="kilometros" size="6" maxlength="6" value="<?php echo $vehiculo->kilometros ?>">
  </td>
 </tr>
 <tr height="25">
  <td>FECHA DE PUBLICACI&Oacute;N <b>(YYYY-MM-DD) </b> </td>
  <td>
<input type="text" name="fecha_pub" id="fecha_public" size="10" maxlength="10" value="<?php echo $vehiculo->fecha_pub ?>"> 
     &nbsp; &nbsp;
    P.M.A.
  <input type="text" name="pma" id="pma" size="5" maxlength="5" value="<?php echo $vehiculo->pma ?>">
  </td>
 </tr>
 <tr height="25">
  <td>PRECIO DE VENTA </td>
  <td>
<input type="text" name="precio_venta" id="pvp" size="6" maxlength="6" value="<?php echo $vehiculo->pvp ?>">
  <td>
 </tr>
 <tr height="25">
 <td>PRECIO NUEVO </td>
  <td>
<input type="text" name="precio_nuevo" id="precio_nuevo" size="6" maxlength="6" value="<?php echo $vehiculo->precio_nuevo ?>">
  <td>
 </tr>
 <tr height="25">
 <td>PRECIO DE COMPRA </td>
  <td>
<input type="text" name="precio_compra" id="precio_compra" size="6" maxlength="6" value="<?php echo $vehiculo->precio_compra ?>">
  <td>
 </tr>
 <tr height="25">
 <td>PUBLICADO </td>
  <td>
<input type="checkbox" name="publicado" id="publicado" value="0">
  <td>
 </tr>
 <tr height="25">
  <td><br />EQUIPAMIENTO </td>
  <td>
  <textarea name="equipamiento" id="equipamiento" value="<?php echo $vehiculo->equipamiento ?>"rows="2" cols="44"> </textarea>
  </td>
 </tr>
 <tr height="25">
 <td>SUBIR FOTOGRAF&Iacute;AS </td>
  <td>
  <input type="file" name="uploadImage" id="uploadImage" action="ficheros.php"/>
  <input type="submit" value="SUBIR" />	
  </td>
 </tr>
 <tr height="25">
 <td>CREAR CARPETA</td>
 <td>
 	  <input name="archivo" type="file" id="archivo" /> 
      <input name="boton" type="submit" id="boton" value="CREAR" />      
     </td>
    </table>
 <p>
   <br/>
    <input type="submit" name="boton" id="boton" value="LIMPIAR" tabindex="14" class="boton" style='width:70px'/>
    <input type="submit" name="boton" id="boton" value="GUARDAR" tabindex="14" class="boton"style='width:100px'/>
    <input type="submit" name="boton" id="boton" value="BORRAR" tabindex="15" class="boton" style='width:100px'/>
    <input type="submit" name="boton" id="boton" value="CARGAR" tabindex="16" class="boton" style='width:100px'/>
    <input type="button" name="volver" id="volver" value="VOLVER" onclick="window.location.href='privado.php'" tabindex="17" class="boton" style='width:80px'/>
</p>  
</form> 
las funciones de los botones son:
Código PHP:
if ($_REQUEST["boton"]=="LIMPIAR"){
            
$vehiculo=new VoDAOClass();
            
$_SESSION["vehiculo"]= $vehiculo;
        }
        if (
$_REQUEST["boton"]=="GUARDAR"){
            
$vehiculo=new VoDAOClass();
            
$vehiculo->matricula=$_REQUEST["matricula"];
            
$vehiculo->marca=$_REQUEST["marca"];
            
$vehiculo->modelo=$_REQUEST["modelo"];
            
$vehiculo->tipo_vehiculo=$_REQUEST["tipo_vehiculo"];
            
$vehiculo->fecha_mat=$_REQUEST["anyo_matricula"];
            
$vehiculo->equipamiento=$_REQUEST["equipamiento"];
            
$vehiculo->fecha_pub=$_REQUEST["fecha_pub"];
            
$vehiculo->kilometros=$_REQUEST["kilometros"];
            
$vehiculo->pma=$_REQUEST["pma"];
            
$vehiculo->pvp=$_REQUEST["precio_venta"];
            
$vehiculo->precio_nuevo=$_REQUEST["precio_nuevo"];
            
$vehiculo->precio_compra=$_REQUEST["precio_compra"];
            
$vehiculo->publicado=$_REQUEST["publicado"];
            
$vehiculo->save();
            
$_SESSION["vehiculo"]= $vehiculo;
        }
        if (
$_REQUEST["boton"]=="BORRAR"){
             
$vehiculo=$_SESSION["vehiculo"];
            
$vehiculo->delete($_REQUEST["matricula"]);
            
$_SESSION["vehiculo"]= new VoDAOClass();
        }
        if (
$_REQUEST["boton"]=="CARGAR"){
            
$vehiculo=new VoDAOClass();
            
$vehiculo->load($_REQUEST["matricula"]);
            
$_SESSION["vehiculo"]= $vehiculo;
        }
        
        if (
$_REQUEST["boton"]=="SUBIR"){
            
$vehiculo=new VpDAOClass();
            
$vehiculo->load($_REQUEST["matricula"]);
            if(!empty(
$_POST)){
      
var_dump(upload_image($_REQUEST["matricula"],'uploadImage'));
            }
        } 
Y la función de subir las imágenes es:
Código PHP:
function upload_image($destination_dir,$name_media_field){
        
$tmp_name $_FILES[$name_media_field]['tmp_name'];
        
//si hemos enviado un directorio que existe realmente y hemos subido el archivo    
        
if ( is_dir($destination_dir) && is_uploaded_file($tmp_name)){
            
$img_file  $_FILES[$name_media_field]['name'] ;
            
$img_type  $_FILES[$name_media_field]['type'];
            echo 
1;
            
//¿es una imágen realmente?           
            
if (((strpos($img_type"gif") || strpos($img_type"jpeg") || strpos($img_type,"jpg")) || strpos($img_type,"png") )){
                
//¿Tenemos permisos para subir la imágen?
                
echo 2;
                if(
move_uploaded_file($tmp_name$destination_dir.'/'.$img_file)){
                    return 
true;
                }
            }
        }
        
//si llegamos hasta aquí es que algo ha fallado
        
return false;
    }
//end function 
Espero que con esto tengas una idea de lo que me falla.

Etiquetas: fichero, formulario
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 11:06.