Php 如何使用codeigniter在数据库中插入图像

Php 如何使用codeigniter在数据库中插入图像,php,codeigniter,phpmyadmin,codeigniter-3,Php,Codeigniter,Phpmyadmin,Codeigniter 3,如何在数据库中插入图像而不上载任何文件夹 我的控制器端代码如下: $data['f_name'] = $this->input->post('f_name'); $data['l_name'] = $this->input->post('l_name'); $data['contact'] = $this->input->post('contact'); $data['email'] = $this->input->post('emai

如何在数据库中插入图像而不上载任何文件夹

我的控制器端代码如下:

$data['f_name'] = $this->input->post('f_name');  
$data['l_name'] = $this->input->post('l_name');  
$data['contact'] = $this->input->post('contact');  
$data['email'] = $this->input->post('email');  
$data['uid'] = $this->input->post('uid');  
//$data['user_image'] = $this->input->post->userfiles['file_name'];  
我的车型侧代码id如下:

$this->db->where('id',$data['uid']);  
$this->db->update('users',array(  
'first_name' =>     $data['f_name'],  
'last_name' =>    $val['l_name'],  
'email'  =>    $val['email'],  
 'phone'  =>    $data['contact']    
));  

图像总是首先上载到临时文件夹。通常,之后它会被存储在一个文件夹中,然后使用PHP函数
move\u upload\u file($filename,$destination)
将其移动到所选的文件夹中。 你可以阅读

如果您想将文件存储在数据库中,我想您可以从临时目录进行存储,但必须自己清理该目录。 重要的是要知道包含数组的变量,该数组包含临时名称和上载名称等详细信息


请注意,可能很难处理数据库以进行移动、复制等操作,特别是如果数据库中存储了许多文件,则会出现任何错误。数据库可以非常快非常大。将图像存储在数据库中不是错误,但这不是常见做法,并且有一些负面影响。至少我会用分离的表将媒体与数据库中的任何数据分离,因此您的决定应该会对数据库设计产生一些影响。

希望这对您有所帮助:

使用
$\u FILES
获取文件名

首先,您的表单应如下所示:

<form action="<?=site_url('controller_name/method_name');?>" enctype="multipart/form-data" method="post" accept-charset="utf-8">

  <input type="file" name="test" id="">

  /*and other input fields*/

  <button type="submit" name="submit">submit</button>
  </form>
更多信息:

可能重复,但我的问题是没有在任何文件夹中上载如何以可变格式获取图像数据您是否检查了我的答案?先生,您是否可以帮助查看浏览器中的图像,如我尝试的表的其他字段图像名称显示,但是如何显示图像呢?因为您必须将图像上传到项目的一个文件夹中,并且显示您必须将图像的路径放在图像的src属性中
public function method_name()
{
   // as you mention u don't want to upload the file

   $file_name = $_FILES['test']['name'];
   $data['user_image'] = $file_name; 

   $data['f_name'] = $this->input->post('f_name');  
   $data['l_name'] = $this->input->post('l_name');  
   $data['contact'] = $this->input->post('contact');  
   $data['email'] = $this->input->post('email');  
   $data['uid'] = $this->input->post('uid');


}