2
到目前爲止,總是爲數據庫中的圖像保存路徑,但是這次我必須將實際圖像保存在數據庫中。我在我的表準備一個字段(LONGBLOB)如何使用codeigniter在mysql中保存圖像?
我有這樣的代碼在我的控制器:
$insertWhat = array(
'dsrequestFileName1' => $this->input->post('dsrequestFileName1'),
'dsrequestFile1' => isset($_FILES['dsrequestFile1']['name'])? $_FILES['dsrequestFile1']['name'] : '',
'dsrequestFileName2' => $this->input->post('dsrequestFileName2'),
'dsrequestFile2' => isset($_FILES['dsrequestFile2']['name'])? $_FILES['dsrequestFile2']['name'] : ''
);
$now = date('Y-m-d-His');
$valid_extensions = array('gif', 'jpg', 'jpeg', 'png', 'bmp','');
if($insertWhat['dsrequestFile1'] !=""){
if (!in_array(end(explode('.', strtolower($_FILES['dsrequestFile1']['name']))), $valid_extensions)) {
$this->session->set_flashdata('wrongtype', '<p class=error>Wrong type of file has been uploaded! Only gif, jpg, bmp and png are allowed.</p>');
redirect('somepage/somefunctionHere');
}
$insertWhat['dsrequestFile1'] = str_replace(' ', '_',$insertWhat['dsrequestFile1']);
$insertWhat['dsrequestFile1'] = $now.$insertWhat['dsrequestFile1'];
}
$config['upload_path'] = 'somefolder/imagesfolder';
$config['allowed_types'] = 'gif|jpg|jpeg|bmp|png';
$config['max_size'] = '2048';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name'] = $insertWhat['dsrequestFile1'];
$this->load->library('upload', $config);
$this->upload->initialize($config);
// perform the upload
$this->upload->do_upload('dsrequestFile1');
$data = array('upload_data' => $this->upload->data('dsrequestFile1'));
// code that saves the insert data is irrelevant to the question, I can post it here if needed however.
然而,這個代碼只上傳圖片。我應該在這裏更改什麼,以便將圖像保存在數據庫中。如果可能的話,我不想上傳圖片。
不幸的是,在CI手冊上沒有任何內容。
重複。請檢查此鏈接http://stackoverflow.com/questions/9737384/code-igniter-how-to-save-images-into-database –
使用查詢來做到這一點。上傳後取文件名,保存在數據庫中。 –
我沒有檢查那個頁面,但是那裏提供的鏈接被破壞了,並且解決方案不起作用。 – user2417624