0

我是 Codeigniter 的新手,我正在尝试用照片库做新闻系统。所有新闻都应该创建一个带有图片的新目录。函数 do_upload () 起作用并创建目录,但函数 get_images () 不起作用。这是我的模型:

function Mdl_tasks() {
 parent::__construct();

$this->gallery_path = realpath(APPPATH . '../images/');
$this->gallery_path_url = base_url().'images/';

}

function do_upload() {
               $this->load->helper('date');
               $folderName = now();
               $pathToUpload = $this->gallery_path . DIRECTORY_SEPARATOR . $folderName;
                if ( ! file_exists($pathToUpload) ) {
                   $create = mkdir($pathToUpload, 0777);
                   $createThumbsFolder = mkdir($pathToUpload . '/thumbs', 0777);
                   if ( ! $create || ! $createThumbsFolder)
                   return;
                   }

        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path' => $pathToUpload,
            'max_size' => 2000,
                        'encrypt_name' => TRUE,
                        'remove_spaces' => TRUE
        );

        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $image_data = $this->upload->data();
                echo 'File upload success!';
                $add['filename'] = $image_data['file_name'];
                $this->db->insert('gallery', $add);

        $config = array(
            'source_image' => $image_data['full_path'],
            'new_image' => $pathToUpload . '/thumbs',
            'maintain_ration' => true,
            'width' => 150,
            'height' => 100
        );

        $this->load->library('image_lib', $config);
        $this->image_lib->resize();

    }

    function get_images() {

                $this->load->helper('date');
                $folderName = now();
                $pathToUpload = $this->gallery_path . DIRECTORY_SEPARATOR . $folderName;
                $pathToThupmUpload = $this->gallery_path_url . DIRECTORY_SEPARATOR . $folderName;

        $files = scandir($pathToUpload);
        $files = array_diff($files, array('.', '..', 'thumbs'));

        $images = array();

        foreach ($files as $file) {
            $images []= array (
                'url' => $pathToThupmUpload . $file,
                'thumb_url' => $pathToThupmUpload . 'thumbs/' . $file
            );
        }

        return $images;
    }

任何想法为什么 get_images() 不起作用?谢谢!

对不起!这是我的 .htaccess 文件:

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
4

1 回答 1

0

尝试改变这一点:

$images = array (
     'url' => $pathToThupmUpload . $file,
      thumb_url' => $pathToThupmUpload . 'thumbs/' . $file
  );

也尝试 print_r$files

于 2013-08-04T11:30:31.233 回答