gpt4 book ai didi

php - 如何在CodeIgniter框架中将图像上传到文件夹并插入到数据库

转载 作者:行者123 更新时间:2023-11-29 19:02:26 24 4
gpt4 key购买 nike

需要将图像上传到文件夹并将文件名插入MySQL,图像名称应该是唯一的。我的 Controller 代码是:

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$config['upload_path'] = 'uploads/gallery/';
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
$this->load->library('upload', $config);
$upload = $this->upload->do_upload('image_file');
$title=$this->input->post('title');
$value=array(
'title' => $title,
'image_name' => $new_image_name,
'crop_name' => $crop_image_name
);
}

最佳答案

这样做

public function uploadImageFile() //gallery insert
{
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$new_image_name = time() . str_replace(str_split(' ()\\/,:*?"<>|'), '',
$_FILES['image_file']['name']);
$config['upload_path'] = 'uploads/gallery/';
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
$config['file_name'] = $new_image_name;
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['$min_width'] = '0';
$config['min_height'] = '0';
$this->load->library('upload', $config);
$upload = $this->upload->do_upload('image_file');
$title=$this->input->post('title');
$value=array('title'=>$title,'image_name'=>
$new_image_name,'crop_name'=>$crop_image_name);}

关于php - 如何在CodeIgniter框架中将图像上传到文件夹并插入到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43758682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com