Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/06/2010, 07:57
Avatar de vdisla
vdisla
 
Fecha de Ingreso: junio-2010
Mensajes: 1
Antigüedad: 13 años, 10 meses
Puntos: 0
Necesito que la variable de imagen se me guarde en la base de datos.

Saludos,

Necesito hacerle una consulta respeto a este punto estoy creando un formulario donde tengo un campo tipo file que conlleva a subir imagen el mismo me sube bien la imagen a un directorio, pero necesito que se me guarde el nombre de la imagen con su extencion en la tabla del campo en cuestion.

le posteo el codigo mas abajo:

Código PHP:
<?php
if($_REQUEST['enviado'] == 1){ 

$imgfile $_POST['imgfile'];

$ruta "./images/" $_FILES['imgfile']['name']; 
copy($_FILES['imgfile']['tmp_name'], $ruta); 
echo 
"<script>alert('El archivo subio correctamente');</script>"
}    
if (!
$_POST){ 
?>
<script> 
<!-- 
function validar(){ 
if(document.getElementById('imgfile').value == ''){ 
alert("Debe seleccionar un archivo"; 
return false; 


--> 
</script>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" enctype="multipart/form-data" onsubmit="return validar(this)">
<table border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td>Titulo:</td>
    <td><input name="titulo" type="text" maxlength="250" size="30" style="border: 1px #d4d4d4 solid" value="<?php echo $_POST["titulo"];?>" /></td>
  </tr>
  <tr>
    <td>Categoria:</td>
    <td><select name="categoria"><option value="Paquetes">Paquetes</option><option value="Ofertas">Ofertas</option><option value="Excursiones">Excursiones</option></select></td>
  </tr>
  <tr>
    <td>Paquetes:</td>
    <td><input name="paquetes" type="text" maxlength="250" size="30" style="border: 1px #d4d4d4 solid" value="<?php echo $_POST["paquetes"];?>" /></td>
  </tr>
  <tr>
    <td>Precio:</td>
    <td><input name="precio" type="text" maxlength="250" size="30" style="border: 1px #d4d4d4 solid" value="<?php echo $_POST["precio"];?>" /></td>
  </tr>
  <tr>
    <td>Imagen:</td>
    <td><input type="hidden" name="MAX_FILE_SIZE" value="50000"><input type="file" name="imgfile" id="imgfile" value="<?php echo $_POST["imgfile"];?>"><input type="hidden" name="enviado" value="1"></td>
  </tr>
  <tr>
   <td colspan="2"><input type="submit" value="Enviar" /></td>
  </tr>
</table>
<?php
}else{

// Primero comprobamos que ningún campo esté vacío y que todos los campos existan.
if(isset($_POST['titulo']) && !empty($_POST['categoria'])) {

// Si entramos es que todo se ha realizado correctamente
$link mysql_connect("localhost","root","123456");
mysql_select_db("ofertas",$link);

// Con esta sentencia SQL insertaremos los datos en la base de datos
mysql_query("INSERT INTO oferta (titulo,categoria,paquetes,precio,imgfile)
VALUES ('{$_POST['titulo']}','{$_POST['categoria']}','{$_POST['paquetes']}','{$_POST['precio']}','{$_POST['imgfile']}')"
,$link);

// Ahora comprobaremos que todo ha ido correctamente
$my_error mysql_error($link);

if(!empty(
$my_error)) {

echo 
"Ha habido un error al insertar los valores. $my_error";

} else {

echo 
"Los datos han sido introducidos satisfactoriamente<div style='float: right; padding: 10px'><a href='javascript:history.back(1)'>Volver Atr&aacute;s</a></div>";

echo 
$_POST['titulo'].'<br>'

echo 
$_POST['categoria'].'<br>';

echo 
$_POST['imgfile'];

}

} else {

echo 
"Error, no ha introducido todos los datos";

}
}
/*$dir=opendir("./images"; 
while ($file=readdir($dir)){ 
$auxiliar = explode(".", $file); 
if($auxiliar[1] == "jpg" 
echo "<img src='images/$file'><br>"; 
} */
?>

Última edición por vdisla; 14/06/2010 a las 12:54