【问题标题】:In Codeigniter Webcam Using upload image in folder and database在 Codeigniter 网络摄像头中使用文件夹和数据库中的上传图像
【发布时间】:2018-07-20 12:20:19
【问题描述】:

查看代码

<button type="button" class="btn btn-info" onClick="take_snapshot()"><i class="fa fa-camera fa-fw"></i>Capture</button>
<div class="col-md-3 col-md-offset-1 imager" id="results" name="results">       
    <input id="results" type="" name="results" value=""/>
    <div class="clearfix" id="my_camera"></div>
    <input type="file" name="webcam">

    function take_snapshot() {                
        Webcam.snap(function (data_uri) {
            document.getElementById('results').innerHTML ='<img src="' + data_uri + '"/>';
        });
        Webcam.upload(data_uri, '"<?php echo base_url(); ?>Enquiry_Management/Demosave"', function(code, text) {
            if (code === '200') {
                alert ('ok');
            } else {
                alert('error');
            }
        });
    }

    Webcam.set({
        width: 320,
        height: 240,
        image_format: 'jpeg',
        upload_name: 'webcam',
        jpeg_quality: 90
    });

    Webcam.attach('#my_camera')

控制器代码

$filename = date('YmdHis').".jpg";
$filepath = FCPATH.'uploads/'.$filename;
$result = move_uploaded_file($_FILES['webcam']['tmp_name'],$filepath);

说明

我想通过网络摄像头点击图像并使用 Codeigniter MVC 框架保存到文件夹和数据库中。这是我的视图和控制器代码。请帮我在控制器中保存和打印图像文件名。

【问题讨论】:

    标签: javascript jquery css html codeigniter


    【解决方案1】:

    看看这个: https://www.codeigniter.com/userguide3/libraries/file_uploading.html

    您可以使用它来将图像上传到您的服务器。

    一个例子:

     $config['upload_path']          = './uploads/';//your path to saving it
                $config['allowed_types']        = 'gif|jpg|png';
                $config['max_size']             = 100;
                $config['max_width']            = 1024;
                $config['max_height']           = 768;
    
                $this->load->library('upload', $config);
    
                if ( ! $this->upload->do_upload('userfile'))//the name of the input. In your case 'webcam' instead of 'userfile'
                {
                        $error = array('error' => $this->upload->display_errors());
    
                        $this->load->view('upload_form', $error);
                }
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2020-09-14
      • 2013-09-05
      • 2016-02-19
      • 1970-01-01
      • 2020-07-06
      • 2016-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多