笨图片上传的MySQL(codeigniter image uploading mysql)

2019-09-02 15:54发布

我想知道如果我在笨的图片上传到数据库将是什么我

$config['upload_path']

我看到所有的例子都使用的文件系统。 我有一个分贝的文章,并希望存储与在数据库中的文章,以及图片。 任何人都可以帮忙吗?

Answer 1:

你可以阅读这个堪称伟大的文章存放在MySQL的图像 。

本文包括以下内容:

  • 这不是一个坏主意?
  • 什么是BLOB?
  • 创建映像表
  • 上传表单
  • 上传图片
  • 上传()函数
  • 从数据库中显示图像
  • 显示所有信息

但是,不要离开你两手空空,看看斑点 ,它是一种数据类型在MySQL colums(和其他各种DBMS)。 这将让你存储数据,如图像和其他二进制文件类型的数据。

在数据库中存储文件和图片的想法是一般同它们存储在文件系统中,上传和具有实际的文件之间,该层仅仅是不同的。

你不能只是设置上传路径,希望一切都解决了,你需要得到一些污垢在你的手中藏汉!



Answer 2:

我张贴在这里希望这有助于有人因为这是旧的文章和答案都没有帮助,此代码的工作对我来说,也是模型部分不在这里,所以你必须弄明白阅读CodeIgniter的文档,我认为这将工作,如果你把它放在你的控制器,也可以把它提交表格必须指向此功能

function upload() {
 $caption = $this->input->post('caption'); 
    $codigo = $this->input->post('codigo');
    //$imagen = $this->input->post('imagen');
    $config['upload_path'] = 'uploads';// this is a directory with 777 permissions where you upload the file
    $config['allowed_types'] = 'gif|jpg|jpeg|png|pdf';
    //$config['max_size'] = '5000';
    $this->load->library('upload', $config);

    if (!$this->upload->do_upload('imagen')) { // this is the input from the form
        echo $this->upload->display_errors();
    } else {
        //here $file_data receives an array that has all the info
        //pertaining to the upload, including 'file_name'
        $file_data = $this->upload->data();

        $fp = fopen($file_data['full_path'], 'r');
        $content = fread($fp, filesize($file_data['full_path']));
        //$content = addslashes($content);
        fclose($fp);
        $data = array( // this is the table i got in my db
            'idBotones' => null,
            'imagen' => $content, //blob image
            'caption' => $caption,
            'codigo' => $codigo
        );

        $this->load->model('generic_model');
        $table = "botones";
        $this->generic_model->insertar_datos($table, $data);
       //print_r($content);
    }
}


Answer 3:

这似乎是最常见的用例在数据库中存储的图像是不是一个好主意。 请看到这两个以前的SO线程:

存储在数据库中的图像:做还是不做

存储DB图像-是啊,还是不是?



文章来源: codeigniter image uploading mysql