Ver Mensaje Individual
  #7 (permalink)  
Antiguo 18/01/2013, 16:43
osito7890
 
Fecha de Ingreso: marzo-2012
Mensajes: 8
Antigüedad: 12 años
Puntos: 0
Respuesta: ¿Se puede agregar una foto a una base de datos mysql?

hola espero que te sirba
Código HTML:
Ver original
  1.  
  2. <form action="upload_file.php" method="post"
  3. enctype="multipart/form-data">
  4. <label for="file">Filename:</label>
  5. <input type="file" name="file" id="file"><br>
  6. <input type="submit" name="submit" value="Submit">
  7. </form>
  8.  
  9. </body>
  10. </html>
Código PHP:
Ver original
  1. <?php
  2. $allowedExts = array("jpg", "jpeg", "gif", "png");
  3. $extension = end(explode(".", $_FILES["file"]["name"]));
  4. if ((($_FILES["file"]["type"] == "image/gif")
  5. || ($_FILES["file"]["type"] == "image/jpeg")
  6. || ($_FILES["file"]["type"] == "image/png")
  7. || ($_FILES["file"]["type"] == "image/pjpeg"))
  8. && ($_FILES["file"]["size"] < 20000)
  9. && in_array($extension, $allowedExts))
  10.   {
  11.   if ($_FILES["file"]["error"] > 0)
  12.     {
  13.     echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
  14.     }
  15.   else
  16.     {
  17.     echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  18.     echo "Type: " . $_FILES["file"]["type"] . "<br>";
  19.     echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  20.     echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
  21.  
  22.     if (file_exists("upload/" . $_FILES["file"]["name"]))
  23.       {
  24.       echo $_FILES["file"]["name"] . " already exists. ";
  25.       }
  26.     else
  27.       {
  28.       move_uploaded_file($_FILES["file"]["tmp_name"],
  29.       "upload/" . $_FILES["file"]["name"]);
  30.       echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  31.       }
  32.     }
  33.   }
  34. else
  35.   {
  36.   echo "Archivo invalido";
  37.   }
  38. ?>

asi podrias solucionar la cuestion de guardado de la imagen y acuanto la base de datos relacionas el nombre o la direccion de almacenamiento y haces un aconsulta y la trae con un link
Código PHP:
Ver original
  1. echo'<a target="new" href".$dato['que trae la base dedatos'].">';
exitos