gpt4 book ai didi

php - 尝试在 codeigniter 的一列中上传两个图像 file_path

转载 作者:行者123 更新时间:2023-11-29 23:36:00 24 4
gpt4 key购买 nike

我正在尝试在一列中上传两个图像文件路径。在我的模型中,我从 $filepath 成功获取第一个图像路径,但 $a 不起作用,我也很困惑 $a 是否正在获取我的第二个图像路径

请帮助我

提前致谢。

我的 Controller

<?php

class upload extends CI_Controller {

function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}

function index()
{
$this->load->view("main_temp/header.php");
$this->load->view('post_ad_views', array('error' => ' ' ));
$this->load->view("main_temp/footer.php");
}

// controller
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name'] = $new_file_name;
$this->load->library('upload', $config);


if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view("main_temp/header.php");
$this->load->view('post_ad_views', $error);
$this->load->view("main_temp/footer.php");
}
else
{
// success
$data = array('upload_data' => $this->upload->data());

// a model that deals with your image data (you have to create this)
$this->load->model('submit_ad_model');
$this->submit_ad_model->ad_post();

$this->load->view('upload_success', $data);


}


}
}
?>

我的模型

<?php
class submit_ad_model extends CI_Model
{

function ad_post()
{

$filepath = $this->upload->data()['file_name'];

$a = $this->upload->data()['file_name'];

$this->db->query("insert into ads (ad_pic) values ('$filepath,$a')");
?>

我的观点

<input type="file" name="userfile" class="upload image"  id="userfile" />
<input type="file" name="userfile2" class="upload image" id="userfile" />

最佳答案

您不想获取第二个上传的项目,您需要使用循环:

       $upload_data = array();
foreach($_FILES as $key => $value){
$this->upload->do_upload($key);
$upload_data[$key] = $this->upload->data($key);
}
$this->submit_ad_model->ad_post($upload_data);

关于php - 尝试在 codeigniter 的一列中上传两个图像 file_path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26374727/

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