Foros del Web » Programando para Internet » PHP »

Problema al subir imágenes a la BD

Estas en el tema de Problema al subir imágenes a la BD en el foro de PHP en Foros del Web. Hola buenas noches. Miren tengo un problema, quiero subir imágenes a mi BD pero no puedo subir imágenes mayor a 1 MB, cambie la configuración ...
  #1 (permalink)  
Antiguo 21/06/2015, 22:47
 
Fecha de Ingreso: junio-2014
Mensajes: 60
Antigüedad: 9 años, 10 meses
Puntos: 0
Problema al subir imágenes a la BD

Hola buenas noches.
Miren tengo un problema, quiero subir imágenes a mi BD pero no puedo subir imágenes mayor a 1 MB, cambie la configuración de mi php.ini y sigue sin dejarme subir archivos mayores, cree el formulario para que no aceptara mayores a 2 MB, pero como ven no puedo ni subir mas de 1 MB, en el log de php me dice lo siguiente:

Código:
[22-Jun-2015 06:37:03 Europe/Berlin] PHP Warning:  mysqli::query(): MySQL server has gone away in C:\xampp\Connection.php on line 35

[22-Jun-2015 06:37:03 Europe/Berlin] PHP Warning:  mysqli::query(): Error reading result set's header in C:\xampp\Connection.php on line 35

Archivo de subida:
Código PHP:
Ver original
  1. <?php
  2. require 'Connection.php';
  3. if(isset($_FILES['imagefile']['tmp_name'])):
  4.     $ImgName = $_FILES['imagefile']['tmp_name'];
  5.     $ImgSize = $_FILES['imagefile']['size'];
  6.     $ImgType = $_FILES['imagefile']['type'];
  7.     $ImgInfo = getimagesize($_FILES['imagefile']['tmp_name']);
  8.     $ImgSecurity = Connection::DataBsEscape(file_get_contents($ImgName));
  9.            
  10.    
  11.     if($ImgName == NULL):
  12.         $msjr = 'Elige un archivo.';
  13.     elseif($ImgSize > 2097152):
  14.         $msjr = 'El archivo no debe ser mayor a 2 MB';
  15.     else:
  16.         if($ImgType == 'image/jpeg' || $ImgType == 'image/pjpeg' || $ImgType == 'image/gif' || $ImgType == 'image/bmp' || $ImgType == 'image/png'):
  17.  
  18.             $ImgQuery = "INSERT INTO imagenes (id, name, anchura, altura, tipo, imagen) VALUES ('".$user['id']."', '".$user['name']."', '".$ImgInfo[0]."', '".$ImgInfo[1]."', '".$ImgType."', '".$ImgSecurity."' )";
  19.             Connection::Querys($ImgQuery);
  20.             $msjg = "Imagen subida";
  21.         else:
  22.             $msjr = "El formato de archivo tiene que ser JPG, GIF, BMP ó PNG.";
  23.         endif;
  24.     endif;
  25. endif;
  26. ?>
  27.  
  28. <form enctype='multipart/form-data' action='' method='post' class='f'>
  29.      <div class='upload'><h3>Seleccionar</h3>
  30.         <input type='file' class='file' name='imagefile'>
  31.     </div>
  32.     <input type='submit' value='Guardar Imagen' >
  33. </form>

Archivo de Conexión:
Código PHP:
Ver original
  1. <?php
  2.  
  3. class Connection {
  4.    
  5.     private static $instance;
  6.     private $DataBs;
  7.    
  8.     private function __construct(array $db) {
  9.  
  10.         $this->DataBs = new mysqli( $db['host'],
  11.                                         $db['user'],
  12.                                         $db['pass'],
  13.                                         $db['name'] );
  14.  
  15.         if (mysqli_connect_errno()) {
  16.             throw new Exception('Database error.');
  17.         }
  18.  
  19.         $this->DataBs->set_charset("utf8");
  20.     }
  21.    
  22.     public static function init(array $db){
  23.         if(self::$instance instanceof self){
  24.             return false;
  25.         }
  26.        
  27.         self::$instance = new self($db);
  28.     }
  29.    
  30.     public static function getMySQLiObject(){
  31.         return self::$instance->DataBs;
  32.     }
  33.            
  34.     public static function Querys($QueRy) {
  35.         return self::$instance->DataBs->query($QueRy);
  36.     }
  37.    
  38.     public static function DataBsEscape($DbEsc) {
  39.         return self::$instance->DataBs->real_escape_string($DbEsc);
  40.     }
  41. }
  42. ?>

¿Pueden echarme una mano?
Gracias.
  #2 (permalink)  
Antiguo 22/06/2015, 07:43
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 11 meses
Puntos: 127
Respuesta: Problema al subir imágenes a la BD

parece ser que tienes un error en la linea 8
y porfacor da un ejemplo de la estructura de tu base;

si te sirve: http://programacion.net/articulo/gua...s_en_mysql_311
  #3 (permalink)  
Antiguo 22/06/2015, 08:06
Avatar de lauser
Moderator Unix/Linux
 
Fecha de Ingreso: julio-2013
Ubicación: Odessa (Ukrania)
Mensajes: 3.278
Antigüedad: 10 años, 9 meses
Puntos: 401
Respuesta: Problema al subir imágenes a la BD

Aparte de lo que te comento @enlinea777.
Puedes definir el tamaño máximo en .htaccess
Código Apache:
Ver original
  1. php_value upload_max_filesize 10M
  2. php_value post_max_size 20M
  3. php_value max_execution_time 360
__________________
Los usuarios que te responden, lo hacen altruistamente y sin ánimo de lucro con el único fin de ayudarte. Se paciente y agradecido.
-SOLOLINUX-

Etiquetas: bd, formulario, mysql, sql
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 08:44.