codeigniter上传图片代码url错误

问题描述 投票:0回答:1

这是关于

的第 9 天的 codeigniter 图像上传和图像处理

http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-file-uploading-and-image-manipulation/

我认为此代码与最新的 CI 不兼容。

我收到错误

“在此服务器上找不到请求的 URL /codeigniter/gallery。”

我的 htaccess 设置为删除 index.php 我已将基本 url 设置为 localhost/codeigniter

型号

<?php
class Gallery_model extends CI_Model {

var $gallery_path;
var $gallery_path_url;

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

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

function do_upload() {

    $config = array(
        'allowed_types' => 'jpg|jpeg|gif|png',
        'upload_path' => $this->gallery_path,
        'max_size' => 2000
    );

    $this->load->library('upload', $config);
    $this->upload->do_upload();
    $image_data = $this->upload->data();

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

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

}

function get_images() {

    $files = scandir($this->gallery_path);
    $files = array_diff($files, array('.', '..', 'thumbs'));

    $images = array();

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

    return $images;
}

}

控制器

<?php
class Gallery extends CI_Controller {

function index() {

    $this->load->model('Gallery_model');

    if ($this->input->post('upload')) {
        $this->Gallery_model->do_upload();
    }

    $data['images'] = $this->Gallery_model->get_images();

    $this->load->view('gallery', $data);

}

}    
php image codeigniter upload codeigniter-2
1个回答
0
投票

你尝试过使用绝对网址吗?

进行测试,而不是

base_url()
使用整个路径
"http://mywebsite.com/path/to/gallery"

如果它适用于绝对 url,则意味着您正在使用旧的 url 路径,然后您可以修复它

© www.soinside.com 2019 - 2024. All rights reserved.