请,我将多个图像移动到目标文件夹,并将图像名称插入用逗号分隔的单个列中。这意味着,所有其他记录将插入到一行中一次,图像的名称将插入到以逗号分隔的列中。从文件上传中移动图像工作正常,但数据未插入数据库。它在下面给出此错误:
遇到 PHP 错误
严重性:通知
消息:数组到字符串的转换
文件名:数据库/DB_driver.php
行号:1465
错误号:1054
">字段列表"中的未知列"数组">
插入wzb_product
(WZB_ProductCode
,ProductGrade
,WZB_ProductName
,WZB_ProductDescription
,WZB_QuantityPerUnit
,WZB_UnitPrice
,WZB_ProductOwner
,WZB_CategoryName
,WZB_VerifiedByAgent
,ProductPhotoName
,Addedby
( 值("PR02_893"、"旧"、"乔瓦尼·维亚利鞋"、"数组"、"空"、"350000"、"管理员"、"包和鞋"、"否"、"主产品01.jpg,主产品02.jpg,主产品03.jpg,主产品04.jpg", "(
事实是我没有名为数组的列。该表单使用 TinyMCE 允许用户键入产品描述。我怀疑图像文件名是罪魁祸首,或者可能是TinyMCE列(ProducrDescription(?
这是我的控制器方法:
$filesCount = count($_FILES['productphotos']['name']);
for($i = 0; $i < $filesCount; $i++)
{
$_FILES['file']['name'] = $_FILES['productphotos']['name'][$i];
$_FILES['file']['type'] = $_FILES['productphotos']['type'][$i];
$_FILES['file']['tmp_name'] = $_FILES['productphotos']['tmp_name'][$i];
$_FILES['file']['error'] = $_FILES['productphotos']['error'][$i];
$_FILES['file']['size'] = $_FILES['productphotos']['size'][$i];
$testprodpath = './Products/Old/BagShoes/';
//$uploadPath = './Products/';
//$uploadPath = base_url().'Products/';
$config['upload_path'] = $testprodpath;
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '5000'; // max_size in kb
$config['file_name'] = $_FILES['productphotos']['name'][$i];
$this->upload->initialize($config);
//load upload library
$this->load->library('upload', $config);
//upload the files
if($this->upload->do_upload('file'))
{
//Get data about the files
$fileData = $this->upload->data();
$name_array[] = $fileData['file_name'];
} // closes if
else
{
echo $this->upload->display_errors();
} //closes else
} //closes for loop
$content = $this->input->post('content');
$datatiny['content'] = $content;
$imagesnames= implode(',', $name_array);
//Insert file information into the database
$data2 = array(
'WZB_ProductCode'=>$this->input->post('productcode'),
'ProductGrade'=>$this->input->post('productgrade'),
'WZB_ProductName'=>$this->input->post('productname'),
'WZB_ProductDescription'=>$datatiny,
'WZB_QuantityPerUnit'=>$this->input->post('quantityperunity'),
'WZB_UnitPrice'=>$this->input->post('unitprice'),
'WZB_ProductOwner'=>$this->input->post('productowner'),
'WZB_CategoryName'=>$this->input->post('productcategory'),
'WZB_VerifiedByAgent'=>$this->input->post('verifiedbyagent'),
'ProductPhotoName'=>$imagesnames,
'Addedby'=>$this->input->post('addedby')
);
$this->db->insert('wzb_product', $data2);
$this->session->set_flashdata('Added Successfully','Record successfully added');
} //closes if for checking if file input has file is submitted and if file is uploaded
我没有使用模型。关键是如果我插入一个不是多个图像的单个图像名称。通过移动图像名称并将带有图像文件名的记录插入数据库,它可以正常工作,但是当它是多个图像时,我会收到此错误。
我提前感谢所有的努力。
问候
您在$datatiny['content']
中有描述,并且在初始化中使用了$datatiny
。它是数组,你不能在其中使用数组。因此,将行更改为:
$data2 = array(
'WZB_ProductCode'=>$this->input->post('productcode'),
'ProductGrade'=>$this->input->post('productgrade'),
'WZB_ProductName'=>$this->input->post('productname'),
'WZB_ProductDescription'=>$datatiny['content'],
'WZB_QuantityPerUnit'=>$this->input->post('quantityperunity'),
'WZB_UnitPrice'=>$this->input->post('unitprice'),
'WZB_ProductOwner'=>$this->input->post('productowner'),
'WZB_CategoryName'=>$this->input->post('productcategory'),
'WZB_VerifiedByAgent'=>$this->input->post('verifiedbyagent'),
'ProductPhotoName'=>$imagesnames,
'Addedby'=>$this->input->post('addedby')
);
你在代码中有一些错误 要么更改此行
$datatiny['content'] = $content;
自
$datatiny = $content;
或将此数组更改为
$data2 = array(
'WZB_ProductCode'=>$this->input->post('productcode'),
'ProductGrade'=>$this->input->post('productgrade'),
'WZB_ProductName'=>$this->input->post('productname'),
'WZB_ProductDescription'=>$datatiny,
'WZB_QuantityPerUnit'=>$this->input->post('quantityperunity'),
'WZB_UnitPrice'=>$this->input->post('unitprice'),
'WZB_ProductOwner'=>$this->input->post('productowner'),
'WZB_CategoryName'=>$this->input->post('productcategory'),
'WZB_VerifiedByAgent'=>$this->input->post('verifiedbyagent'),
'ProductPhotoName'=>$imagesnames,
'Addedby'=>$this->input->post('addedby')
);
自
$data2 = array(
'WZB_ProductCode'=>$this->input->post('productcode'),
'ProductGrade'=>$this->input->post('productgrade'),
'WZB_ProductName'=>$this->input->post('productname'),
'WZB_ProductDescription'=>$datatiny['content'],
'WZB_QuantityPerUnit'=>$this->input->post('quantityperunity'),
'WZB_UnitPrice'=>$this->input->post('unitprice'),
'WZB_ProductOwner'=>$this->input->post('productowner'),
'WZB_CategoryName'=>$this->input->post('productcategory'),
'WZB_VerifiedByAgent'=>$this->input->post('verifiedbyagent'),
'ProductPhotoName'=>$imagesnames,
'Addedby'=>$this->input->post('addedby')
);