Php CodeIgniter-通过表单上传图像,将图像的位置存储在数据库中
我正试图通过表单将图像上传到我的站点,但是将图像的位置存储在数据库中(而不是使数据库陷入困境)效率更高 我的表格有问题,真的不知道该去哪里:Php CodeIgniter-通过表单上传图像,将图像的位置存储在数据库中,php,mysql,file,codeigniter,upload,Php,Mysql,File,Codeigniter,Upload,我正试图通过表单将图像上传到我的站点,但是将图像的位置存储在数据库中(而不是使数据库陷入困境)效率更高 我的表格有问题,真的不知道该去哪里: <?=form_open('bro/submit_new');?> //other form data Image: <input type="file" name="image" size="20" /> <br> <input type="submit" value="Submit" /> <
<?=form_open('bro/submit_new');?>
//other form data
Image: <input type="file" name="image" size="20" /> <br>
<input type="submit" value="Submit" />
</form>
CodeIgniter的文件上传类将为您完成此任务。我尽我所能解释清楚了,所以我要告诉你
基本上,您只需要修改控制器,使其包含一个将文件URL放入数据库的位置,您可以通过使用$this->upload->data()并从结果数组中提取[full_path],然后将其发送到处理数据库输入的模型来轻松完成此操作。使用form_open_multipart()不是form_open()使用模型页面将数据上载到数据库我的印象是它直接将文件加载到数据库中?我错了吗?但我想我没有想到为什么它会将它同时加载到两个位置。不,它会将它上载到您指定的任何目录:)阅读用户指南!呵呵。一点也不愚蠢。用户指南对每个人来说都有点大,可以让他们了解CodeIgniter的所有内容。
function submit_new(){
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->db->insert('post', $_POST);
redirect('bro');
}