0

これはファイルアップロードの基本機能です。すべての画像名を含む文字列を返す必要があります。アップロードする画像がない場合は、FALSEを返します。これどうやってするの?

function img_upload($folder) {
            $this->path = './public/img/' . $folder;
            $imgs = array();
            $g = true;
            $config = array(
                'allowed_types' => 'jpg|jpeg|png|gif',
                'upload_path' => $this->path
            );
            $CI = &get_instance();
            $CI->load->library('upload', $config);
            foreach ($_FILES as $key => $value) {

                if (!$CI->upload->do_upload($key)) {
                    return FALSE;
                } else {
                    $q = $CI->upload->data();
                    $config['image_library'] = 'gd2';
                    $config['source_image'] = $this->path . '/' . $q['file_name'];
                    $config['new_image'] = $this->path . '/thumbs';
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = TRUE;
                    $config['width'] = 128;
                    $config['height'] = 128;

                    $CI->load->library('image_lib', $config);
                    $CI->image_lib->resize();
                    echo $q['file_name'];                
                    $imgs = array_push($imgs, $q['file_name']);
                }      
            }        
        }
4

1 に答える 1

1

このコードがあなたを助けるかもしれないよりもあなたが正しいことを理解していれば..

 function img_upload($folder) {
            $this->path = './public/img/' . $folder;
            $imgs = array();
            $g = true;
            $config = array(
                'allowed_types' => 'jpg|jpeg|png|gif',
                'upload_path' => $this->path
            );
            $CI = &get_instance();
            $CI->load->library('upload', $config);
            foreach ($_FILES as $key => $value) {

                if (!$CI->upload->do_upload($key)) {
                    return FALSE;
            } else {
                $q = $CI->upload->data();
                $config['image_library'] = 'gd2';
                $config['source_image'] = $this->path . '/' . $q['file_name'];
                $allimages = array();
                $allimages = $q['file_name'];
                $config['new_image'] = $this->path . '/thumbs';
                $config['create_thumb'] = FALSE;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 128;
                $config['height'] = 128;

                $CI->load->library('image_lib', $config);
                $CI->image_lib->resize();
                echo $q['file_name'];                
                $imgs = array_push($imgs, $q['file_name']);


                 if(count($allimages) > 0)
                   {
                     return $allimagename = ('',$allimages);
                   }
                 else
                   {
                     return 'Thre is no images';
                    }
                }      
            }        
        }
于 2012-06-06T10:33:52.847 に答える