Codeigniter更新数据库列中的新映像而不替换旧映像

时间:2016-12-07 05:31:18

标签: mysql codeigniter image-uploading

我正在更新图片文件,但是当我更新新版本时,它会替换旧版本。我想保留所有图片文件而不更换。

例如

if i remove one of them and add new one it update column value with one and remove old one..i need all of them.

如果我删除其中一个并添加新的一个,则用一个更新列值并删除旧的..我需要所有这些。

此处我的上传代码:

$picture=array();
$cpt = count($_FILES['my_image_upload']['name']);
$config['upload_path'] = APPPATH.'uploads/';
$config['allowed_types'] = '*';
$files = $_FILES;
for($i=0; $i<$cpt; $i++)
{       
 if($_FILES['my_image_upload']['name'][$i]!='')
    {   
    $_FILES['my_image_upload']['name']= $files['my_image_upload']['name'][$i]; 
    $_FILES['my_image_upload']['type']= $files['my_image_upload']['type'][$i];
    $_FILES['my_image_upload']['tmp_name']= $files['my_image_upload']['tmp_name'][$i];
    $_FILES['my_image_upload']['error']= $files['my_image_upload']['error'][$i];
    $_FILES['my_image_upload']['size']= $files['my_image_upload']['size'][$i];
    $this->load->library('upload', $config);
    $this->upload->initialize($config);
    $upload= $this->upload->do_upload('my_image_upload');
    if($upload)
        {
           $this->upload->data();
           $picture[] =$_FILES['my_image_upload']['name'];
        }
     }
 }
$fileName = implode('|',$picture);

提前致谢..

1 个答案:

答案 0 :(得分:0)

我建议像这样创建新表并插入数据......

id   user_id    image_name  
1       2       abc.jpg 
2       2       bbb.jpg 
3       2       ccc.jpg 
.........

以简单的方式插入更新删除,如您所愿