我正嘗試創建一個跨平臺的應用程序,並且我想使用Codeigiter將不同設備中的圖像保存在數據庫中。我可以從設備中選擇圖像,但是我很困惑並且不知道如何保存圖像並從數據庫中檢索圖像。將圖像保存到數據庫中無法正常工作
控制器
function addstatesoothing() {
// write user data into the user database
$config['upload_path'] = './';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000000';
$config['overwrite'] = TRUE;
$config['remove_spaces'] = TRUE;
$config['encrypt_name'] = FALSE;
$this->load->library('upload', $config);
$image_path = $this->upload->data('soothing-img');
$data = array(
'soothing-img' => $image_path[full_path],
'soothing-title' => $this->input->post('soothing-title'),
);
$this->favourite_db->addstatesoothing($data);
$this->load->view('soothing');
}
型號
function addstatesoothing($data) {
$this->load->database();
$this->db->insert('soothing', $data);
return $data;
}
查看
<form method="post" action="addstatesoothing">
<!-- <button data-theme="d" onclick="capturePhoto();">Capture Photo</button> -->
<a data-theme="d" onclick="getPhoto(pictureSource.PHOTOLIBRARY);">Click to Add Pictures</a>
<img style="width:100%;" id="largeImage" src="" name="soothing-img"/> <br>
<input type="text" name="soothing-title" id="Climbed a Mountain" value="" placeholder="Climbed a Mountain"/>
<button data-theme="a">Save Memory</button>
</form>
混淆和庫存並不可以在這裏解決了一個問題,所以你有什麼編程問題? –
上面的代碼不會保存圖像文件在數據庫中 – Omade
啊,我以爲'$ this-> db-> insert('soothing',$ data);'這樣做了,但有人已經做好了你的功課;-) –