0
這是我的代碼,我想在數據庫中動態添加圖像。我怎樣才能做到這一點?basename()期望參數1是字符串數組給定codeigniter
這是我的控制器
if($this->input->post('title'))
{
$values['prootherinfo']=$this->AdminModel->select_table('pro_otherinfo');
foreach($values['prootherinfo']->result() as $r)
$image=$r->othr_info_image;
$path=FCPATH."assets/images/".$image;
unlink($path);
$target_dir = FCPATH."assets/images/";
$arrfile = pos($_FILES);
$target_file = $target_dir . basename($_FILES["userfile"]["name"]);
move_uploaded_file($_FILES["userfile"]["tmp_name"], $target_file);
$title = $this->input->post('title', true);
$desc = $this->input->post('desc', true);
$proid = $this->input->post('pro_id', true);
foreach ($title as $i => $a) { // need index to match other properties
foreach ($desc as $dd => $d)
$keyt = array(
'othr_info_image'=>$_FILES["userfile"]["name"],
'title' => $a,
'description' => $d,
'pro_id' => $proid
);
//print_r($keyt);
if (!$this->db->insert('pro_otherinfo', $keyt)) {
// quit if insert fails - adjust accordingly
print_r($keyt);
die('Failed insert');
}
}
}
這是我的看法
<input type="file" name="userfile[]">
請刪除頂部的重複文本,詢問實際問題並查看:https://stackoverflow.com/help/mcve –
調試什麼是'basename($ _ FILES [「userfile」] [「name 「]'你會看到要改變的。 – Tpojka