今天的學習

今天學到了用ci框架向數據庫添加數據,代碼是這樣的:php

$picture = $this->input->post('picture');
$price = $this->input->post('price');
$name = $this->input->post('name');
$standard = $this->input->post('standard');
$content = $this->input->post('content');
$link = $this->input->post('link');

$data = array(
	'image_url' => $picture,
	'price' => $price,
	'name' => $name,
	'standard' => $standard,
	'content' => $content,
	'link' => $link,
);
$this->db->insert('add', $data);

還學到了將圖片存到指定文件夾,路徑上傳到數據庫,代碼以下:ajax

//上傳到指定文件夾
$filename = time() . rand(0, 10000);

$filename .= '.' . explode('.', $_FILES['youFile']['name'])[1];
$filePath = base_url() . '/upankh/' . $filename;
$config['upload_path'] = './upankh/';
$config['file_name'] = $filename;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload', $config);
if ($this->upload->do_upload('youFile') == true) {
	$data = [];
	$data['status'] = 1;
	$data['message'] = '上傳成功';
	$data['filePath'] = $filePath;
	$this->ajaxResult($data);
}
相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息