ugursemizoglu ugursemizoglu - 4 months ago 17
PHP Question

Codeigniter if id = 1 it works multiple image update but id =2 it's not working

My codes multiple image upload and update mysql db but one problem if id=1 It's working multiple image uploading and update.else It's not working and white page.

tables 2

musteri_soru and musteri_cevap

is updating musteri_cevap in colon resim

controller code:

function duzenle($no)
{
if($_POST)
{
$arr1['baslik'] = $this->input->post('soru');
$this->form_duzenle_model->duzenle($no,$arr1);

if($_FILES){

$dizin= "../upload/form_cevap/";
$dosya_sayi=count($_FILES['cevap']['name']);

for($i=0;$i<=$dosya_sayi;$i++){
$isim= md5(uniqid(rand()));
if(!empty($_FILES['cevap']['name'][$i])){
move_uploaded_file($_FILES['cevap']['tmp_name'][$i],"./$dizin/$isim{$_FILES['cevap']['name'][$i]}");
$arr['resim']= $dizin.$isim.$_FILES['cevap']['name'][$i];
}
$approve[] = $arr['resim'];
$it = $approve;
print_r($approve);

foreach($it as $n => $c):

/* $deneme = $this->form_duzenle_model->cevapDuzenle($n,$c); */
endforeach;
}
}

redirect('form_duzenle/', 'refresh');
}else{
$this->bc->addCrumb('Düzenle');
$veri = $this->form_duzenle_model->form_duzenleGetir($no)->row();
$veri2 = $this->form_duzenle_model->cevapListe($no)->result();
$data = array(
'baslik'=>$veri->baslik,
'veri' =>$veri,
'cevap' =>$veri2
);
$this->bc->addCrumb($veri->baslik,'form_duzenle/duzenle/'.$veri->no);
$this->layout->view('form_duzenle/form_duzenle_duzenle',$data);
}
}


Models code :

function duzenle($no,$data)
{
$this->db->update($this->tablo,$data, array('no' => $no));
}

function cevapDuzenle($n,$dat)
{
$data = array('resim' => $dat);
$this->db->update($this->ctablo,$data, array('soru_no' => $n));
}


My Tables

enter link description here

Answer

To be honest, I'm not quite sure how your upload was working as the $_FILES array shouldn't be nesting the uploads in the way you've shown above.

I'm not saying this will definitely work but it should do:

function duzenle($no)
{

    //I would possible look at using the Form_validation Library here
    if (empty($_POST)) {
        $arr1['baslik'] = $this->input->post('soru');
        $this->form_duzenle_model->duzenle($no, $arr1);

        if (!empty($_FILES)) {
            $dizin = "../upload/form_cevap/";

            foreach ($_FILES as $name => $file) {

                //If there is an error there isn't any reason to try and upload this file
                if ($file['error'] !== 0) {
                    continue;
                }

                $name = $file['name'];
                $isim = md5(uniqid(rand()));
                move_uploaded_file($file['tmp_name'], "./$dizin/$isim$name");
                $arr['resim'] = $dizin . $isim . $name;

                //Not sure what's going on here so I haven't changed it
                $approve[] = $arr['resim'];
                $it = $approve;
                print_r($approve);

                foreach ($it as $n => $c):

                /* $deneme = $this->form_duzenle_model->cevapDuzenle($n,$c); */
                endforeach;
            }
        }


        redirect('form_duzenle/', 'refresh');
    }else {
        $this->bc->addCrumb('Düzenle');
        $veri = $this->form_duzenle_model->form_duzenleGetir($no)->row();
        $veri2 = $this->form_duzenle_model->cevapListe($no)->result();
        $data = array(
            'baslik' => $veri->baslik,
            'veri' => $veri,
            'cevap' => $veri2
        );
        $this->bc->addCrumb($veri->baslik, 'form_duzenle/duzenle/' . $veri->no);
        $this->layout->view('form_duzenle/form_duzenle_duzenle', $data);
    }
}

Hope this helps!