在PHP和Codeigniter中成功删除多个图像后,unlink不会给出此类文件或目录警告

时间:2018-07-10 07:57:01

标签: php codeigniter-3

<?php
//Controller Code to update gallery images.

$gallery_images = $data['$previous_product_gallery_images'] = $this->ProductModel->get_gallery_images($this->input->post('product_id'));


//Update Gallery Images

$count_gallery_images = count($_FILES['gallery_images']['name']);

if ($count_gallery_images) {

    for ($i = 0; $i < $count_gallery_images; $i++) {

        foreach ($gallery_images as $gallery_image) {

            $file = './assets/images/gallery_images/'.$gallery_image['gallery_image_name'];

            chmod('./assets/images/gallery_images', 0777);

            unlink($file);

        }

        $_FILES['userfile']['name'] = $_FILES['gallery_images']['name'][$i];
        $_FILES['userfile']['type'] = $_FILES['gallery_images']['type'][$i];
        $_FILES['userfile']['tmp_name'] = $_FILES['gallery_images']['tmp_name'][$i];
        $_FILES['userfile']['error'] = $_FILES['gallery_images']['error'][$i];
        $_FILES['userfile']['size'] = $_FILES['gallery_images']['size'][$i];

        $config = array();
        $config['upload_path'] = './assets/images/gallery_images';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size'] = '100000';
        $config['max_width'] = '5000';
        $config['max_height'] = '5000';
        $this->load->library('upload', $config, 'gallery_image');
        $this->gallery_image->initialize($config);
        $upload_gallery_image = $this->gallery_image->do_upload('userfile');

        if ($upload_gallery_image) {

            $gallery_image_name = $_FILES['userfile']['name'];
            $this->ProductModel->update_gallery_image($gallery_image_name, $this->input->post('product_id'));


        }

    }
}


//

0 个答案:

没有答案