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 回答