Ver Mensaje Individual
  #4 (permalink)  
Antiguo 07/05/2014, 09:25
K1R4MC
 
Fecha de Ingreso: abril-2014
Mensajes: 56
Antigüedad: 10 años
Puntos: 0
Respuesta: ¿Como crear un cambia portadas como facebook?

Pero ya pude con solo php fue algo asi:
imagenes.php:
Código PHP:
Ver original
  1. <?php
  2.     include('../Kira/configuracion.php');
  3.  
  4.     if (isset($_POST['guardar']))
  5.     {
  6.         $nombre = $_FILES['imagen']['name'];
  7.         $imagen_temporal = $_FILES['imagen']['tmp_name'];
  8.         $type = $_FILES['imagen']['type'];
  9.  
  10.         $itmp = fopen($imagen_temporal, 'r+b');
  11.         $imagen = fread($itmp, filesize($imagen_temporal));
  12.         fclose($itmp);
  13.  
  14.         $imagen = mysql_real_escape_string($imagen);       
  15.         $respuesta = mysql_query("insert into subir_imagen (id, nombre_imagen, imagen, tipo)
  16.         values(0, '$nombre', '$imagen', '$type')", $link);
  17.  
  18.         header("Location: imagenes?".($respuesta ? 'ok' : 'error'));
  19.     }
  20.    
  21.     if (isset($_GET['ok']))
  22.     {
  23.         echo '<p>Guardado Exitosamente</p>';   
  24.     }
  25.    
  26.     if (isset($_GET['error']))
  27.     {
  28.         echo '<p>Ocurrio un error a la hora de realizar la insercion...</p>';  
  29.     }
  30.  
  31.     echo '
  32.     <form action="imagenes" enctype="multipart/form-data" method="post" style="position: relative;top: 350px;left: 485px;">
  33.         <input type="file" name="imagen" id="imagen" />
  34.         <input type="submit" value="Guardar" name="guardar" />
  35.     </form>';
  36.    
  37.     $sql = mysql_query("select id, nombre_imagen, imagen from subir_imagen", $link);
  38.     $imagenes = array();
  39.     while($row = mysql_fetch_assoc($sql))
  40.     {
  41.         $imagenes[$row['id']] = array(
  42.             'id' => (int) $row['id'],
  43.             'nombre' => $row['nombre_imagen'],
  44.             'imagen' => $row['imagen'],
  45.         );
  46.     }
  47.    
  48.     if (!empty($imagenes))
  49.     {
  50.         echo '<span style="text-decoration:underline; position:relative; top: 310px; left:300px;">Cambia tu foto de portada</span>';
  51.         foreach($imagenes as $valor)
  52.             echo '<p>', '<img src="ver?i=', $valor['id'] , '">' , '</p>';
  53.     }
  54. ?>
  55. <html>
  56. <head>
  57.     <title><?php echo $CH['title']; ?>: Mis Imagenes</title>
  58. </head>
  59. <body>
  60.  
  61. </body>
  62. </html>
y en ver.php:
Código PHP:
Ver original
  1. <?php
  2.     //conexion a la base de datos
  3. include('../Kira/configuracion.php');
  4.  
  5.     //si enviamos por parametro la id
  6.     $id = (int) $_GET['i'];
  7.    
  8.     //no hay id
  9.     if (empty($id))
  10.         //redireccionamos
  11.         header("Location: me");
  12.        
  13.     $sql = mysql_query("select id, imagen, tipo from subir_imagen where id = $id", $link);
  14.     $imagenes = array();
  15.     while($row = mysql_fetch_assoc($sql))
  16.         $imagenes[$row['id']] = array(
  17.             'id' => $row['id'],
  18.             'imagen' => $row['imagen'],
  19.             'tipo' => $row['tipo'],
  20.         );
  21.     //existen imagenes para mostrar?
  22.     if (!empty($imagenes))
  23.     {
  24.         header("Content-Type: ".$imagenes[$id]['tipo']);
  25.         echo $imagenes[$id]['imagen'];
  26.     }
  27. ?>
AHORA LO QUE QUISIERA SABER ES COMO HACER QUE CUANDO SE SUBA UNA NUEVA IMAGEN SE REMPLASE ESA POR LA NUEVA Y QUE CADA USUARIO PUEDA CAMBIAR A VOLUNTAD SIN AFECTAR A LOS DEMAS ESTA ES MI TABLA:
Código MySQL:
Ver original
  1. CREATE TABLE IF NOT EXISTS `subir_imagen` (
  2.   `id` int(11) NOT NULL AUTO_INCREMENT,
  3.   `nombre_imagen` text NOT NULL,
  4.   `imagen` mediumblob NOT NULL,
  5.   `tipo` text NOT NULL,
  6.   PRIMARY KEY (`id`)
  7. )