首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用codeigniter上传时,mysql中不提供镜像

使用codeigniter上传时,mysql中不提供镜像
EN

Stack Overflow用户
提问于 2018-07-25 02:24:45
回答 2查看 53关注 0票数 -1
  1. 问题:尝试通过codeigniter服务在mysql数据库字段(BLOB)中存储镜像时,MySql未启用该镜像。(我知道这不是一种好的做法,但却是必须的)。什么时候是上传镜像通过mysl管理,镜像它的ok。
  2. 我如何测试?我使用postman,它有几个文本字段和一个“文件”字段,我将图像保存在数据库中。

Postman

  1. 测试结果:所有文本字段都存储在数据库中,文件字段按预期上传到目录中,但二进制数据没有存储在数据库中的字段foto中

Results in MySql

Codeigneter:中的

  1. 代码

代码语言:javascript
复制
public function CrearCliente(){
    $user = $this->input->post('user');
    $nombre = $this->input->post('nombre');
    $apellido = $this->input->post('apellido');
    $rut = $this->input->post('rut'); 
    $correo = $this->input->post('correo');
    $id_pais = $this->input->post('id_pais');
    $fecha = $this->input->post('creacion');
    $password = $this->input->post('password');
    $presentacion = $this->input->post('presentacion'); 
    $telefono = $this->input->post('telefono'); 
    $long = 0;
    $lat = 0;
    $res="null";
		$this->load->library('form_validation');
		$mimetypes = array("image/jpeg", "image/pjpeg", "image/gif", "image/png");
		$foto = $_FILES['foto']['name'];
		$tamanio = $_FILES['foto']["size"];
		$archivo = $_FILES['foto']['tmp_name'];
		$type = $_FILES['foto']['type'];
		$imagen = fopen($archivo, 'rb');
    $contenido2 = fread($imagen, $tamanio);
  	$contenido=file_get_contents($archivo,TRUE);
		$contenido3 = $this->db->escape_str($contenido);
	  fclose($imagen);
		if(!in_array($type, $mimetypes))
    											die("El archivo que subiste no es una imagen válida");
                          
		$config['upload_path'] = './imagenes/';
		$config['allowed_types'] = 'gif|jpg|jpeg|png';
		$config['max_size'] = '5000000';
		$config['quality'] = '90%';
		$config['overwrite'] = TRUE;
		$config['max_width']            = 1024;
    $config['max_height']           = 768;
		$config['file_name'] = $foto;
		$this->load->library('upload', $config);
		if (!$this->upload->do_upload('foto')) {
								$error = array('error' => $this->upload->display_errors());
								$data['uploadError'] = $this->upload->display_errors();
								die('error');
                }
		else{
								$data = array('upload_data' => $this->upload->data());
										}
		
    $this->load->model('Usuario');
    $res = $this->Usuario->InsertUsuario($contenido3,$user, $nombre, $apellido,$rut, $correo, $foto,$tamanio,$id_pais,$fecha,$password,$presentacion,$telefono,$long,$lat);   //	*se le asigna una variable al modelo para guardar el contenido que retorna la bd
    header('content-type: application/json'); //* se colcoa una cabezera para decir que se va a retornar un Json
    echo json_encode($res);		
   }




function InsertUsuario($contenido,$user, $nombre, $apellido,$rut, $correo, $foto,$tamanio,$id_pais,$fecha,$password,$presentacion,$telefono,$long,$lat)
   {
   
     $hoy=getdate();   
     if ($foto) {
       echo $contenido;
       
      }
    else{
       $imagen = null;
       header('content-type: application/json');
       echo json_encode("./upload/error.jpg");
    }   
     $this->db->trans_strict(TRUE);
     $this->db->trans_start();   
     $data = array(
         'user'          =>   $user,
         'nombre'          =>   $nombre,
         'apellido'          =>   $apellido,
         'id_rut'          =>   $rut,
         'correo'          =>   $correo,
         'foto'          =>   $contenido,
         'id_pais'          =>   $id_pais,
         'password'          =>   $password,
         'presentacion'  =>    $presentacion,
         'telefono'  =>    $telefono,
         'creacion'          =>   $fecha,
         'long'          =>   $long,
         'lat'          =>   $lat
         );
  
         $this->db->insert('wm_clientes',$data);
         $this->db->trans_complete();
         if ($this->db->trans_status() === FALSE)
             {
               return $res='ERROR';
             }
             else
             {
               return $res='OK';
             }
   }

  1. 问题:为什么与图像(jpg)文件相关的数据不存储在数据库中?检查图像。我尝试了很多东西,但看起来比我预期的更难。需要帮助大师!strong text
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51505294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档