Tema: Imagen mysql
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/08/2012, 10:36
Maikol86
 
Fecha de Ingreso: mayo-2012
Mensajes: 21
Antigüedad: 12 años
Puntos: 1
Imagen mysql

Hola, necesito que alguien me eche una mano. Mi intencion es subir una foto a un directorio a traves de un formulario (hasta aqui bien), pero al mismo tiempo quiero insertar la ruta de la imagen en mysql ¿que sentencia necesito? Este es mi codigo:

index.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Subir archivos</title>
<link rel="STYLESHEET" type="text/css" href="estilos_admin.css">
</head>

<body>
<h1>Subir archivos</h1>
<br>
<form action="subearchivo.php" method="post" enctype="multipart/form-data">
<b>Campo de tipo texto:</b>
<br>
<input type="text" name="cadenatexto" size="20" maxlength="100">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<br>
<br>
<b>Enviar un nuevo archivo: </b>
<br>
<input name="userfile" type="file">
<br>
<input type="submit" value="Enviar">
</form>
</body>
</html>


subearchivo.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Subiendo una nueva foto</title>
<link rel="STYLESHEET" type="text/css" href="estilos_admin.css">
</head>

<body>
<h1>Subiendo un archivo</h1>
<br>
<div align="center">
<?
//tomo el valor de un elemento de tipo texto del formulario
$cadenatexto = $_POST["cadenatexto"];
echo "Escribi&oacute; en el campo de texto: " . $cadenatexto . "<br><br>";

//datos del arhivo
$nombre_archivo = $_FILES['userfile']['name'];
$tipo_archivo = $_FILES['userfile']['type'];
$tamano_archivo = $_FILES['userfile']['size'];
//compruebo si las características del archivo son las que deseo
if (!((strpos($tipo_archivo, "gif") || strpos($tipo_archivo, "jpeg") || strpos($tipo_archivo, "png")) && ($tamano_archivo < 100000))) {
echo "La extensión o el tamaño de los archivos no es correcta. <br><br><table><tr><td><li>Se permiten archivos .gif, .jpg o .png<br><li>se permiten archivos de 100 Kb máximo.</td></tr></table>";
}else{
if (move_uploaded_file($_FILES['userfile']['tmp_name'], 'imagen_upload/'.$nombre_archivo)){
echo "El archivo ha sido cargado correctamente.";
}else{
echo "Ocurri&oacute; alg&uacute;n error al subir el fichero. No pudo guardarse.";
}
}
?>
<br>
<br>

<a href="index.php">Volver</a>
<br>
</div>
</body>
</html>

Gracias