查看代码
<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);
说明
我要成像单击Webcam,然后使用Codeigniter MVC框架保存到文件夹和数据库中。这是我的视图和控制器代码。请帮助我在控制器中保存和打印图像文件名。
答案 0 :(得分:0)
看看这个: 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);
}
希望这会有所帮助!