今天的学习

今天学到了用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);
}
相关文章
相关标签/搜索
本站公众号
   欢迎关注本站公众号,获取更多信息