Codeigniter update new image in database column without replace old one

北城余情 提交于 2019-12-23 04:55:18

问题


I am updating image files but when i update new one it replace old one.i want to keep all without replacing.

for example

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.

Here My Upload Code:

$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);

Thanks in advance..


回答1:


i suggest create new table like this and insert data...

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

and in simple way insert, update and delete as you wish



来源:https://stackoverflow.com/questions/41010082/codeigniter-update-new-image-in-database-column-without-replace-old-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!