Codeigneter:中的
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';
}
}
https://stackoverflow.com/questions/51505294
复制相似问题