簡體   English   中英

使用codeigniter上載多個圖像,調整大小並保存到數據庫

[英]Multiple image upload, resize and saveinto db using codeigniter

我正在嘗試使用codeigniter上傳多個圖像。 這是場景 在此處輸入圖片說明

如何上傳多張圖片並將圖片位置保存到db中(因為我想在視圖文件中顯示上傳的圖片),並且在上傳之前我還想重命名圖片並將其大小調整為“縮略圖”大小。

這是我的控制器:

    function uploadRoomImage(){

    $i = 0;
    $files = array();
    foreach ($_FILES as $key => $value) {
        if(!empty($value['name']))
        {

            $config['upload_path'] = 'assets/img/upload/rooms/';
            $config['allowed_types'] = 'jpg|jpeg';
            $config['file_name'] = $filename;
            $config['max_size'] = '2000';
            $config['remove_spaces'] = true;
            $config['overwrite'] = false;

            $this->upload->initialize($config);

            if (!$this->upload->do_upload($key))
            {
                $error = array('error' => $this->upload->display_errors());
            }
            else
            {
                $files[$i] = $this->upload->data();
                $i++;

                //load image library
                $this->load->library('image_lib');

                $config['image_library'] = 'gd2';
                $config['source_image'] = $image_data['full_path'];
                $config['new_image'] = $image_data['file_path'].'room_thumb/';
                $config['maintain_ratio'] = FALSE;
                $config['create_thumb'] = TRUE;
                $config['thumb_marker'] = '_thumb';
                // $config['overwrite'] = false;
                $config['width'] = 280;
                $config['height'] = 280;

                //initialize upload library using the config settings defined above.
                $this->image_lib->initialize($config);

                if (!$this->image_lib->resize()) {
                    $error = array('error' => $this->image_lib->display_errors());
                } else {
                    $this->image_lib->resize();
                }
                //i want send each image file location into db in here after resizing each image
            }
        }           
    }       

我可以上傳多張圖片,但無法將其位置發送到我的數據庫中,也無法調整它們的大小。 請幫助

看起來您的$config['source_image'] = $image_data['full_path']; 缺少附加到完整路徑的文件名。 您還應該在$config['new_image']

如果要將數據上傳到數據庫,則可以創建一個處理該操作的模型

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM