0

我正在使用 Code Igniter 框架中的上传库创建一些文件上传功能,但我遇到了一个问题,我不断收到错误消息,指出我的文件上传路径不正确。我检查了很多次,文件结构没有问题,文件肯定存在。

这是我的模型上传代码(我很想检查我在这个过程中的位置):

class Gallery_model extends CI_Model {

    var $gallery_path;

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

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

    }

    public function doUpload() {
        $config = array(
            'allowed_types' => 'jpg|jpeg|png|gif',
            'upload_path'   => $this->gallery_path
        );
        $this->load->library('upload', $config);
        if($this->upload->do_upload()) {
            $data = array('upload_data' => $this->upload->data());
            die(print_R($data));
        } else {
            $error = array('error' => $this->upload->display_errors());
            die(print_R($error));
        }
    }

}

我的图像文件夹位于应用程序之外,称为“图像”,其中包含一个名为“profileImage”的文件夹,我希望在其中保存这些文件。我收到以下错误:

“上传路径似乎无效。”

我一生都无法弄清楚为什么这条路确实存在时行不通。有没有人有任何想法?谢谢

4

2 回答 2

3

$config['upload_path']如果为空或 php 命令is_dir($config['upload_path'])返回 false ,Codeigniter 只会返回该错误消息。检查以确保“上传”文件夹与主 index.php 文件位于同一目录中,并且目录名称大小写相同

于 2013-08-14T12:59:58.660 回答
1

您的图像文件夹在网络根目录中吗?如果这应该工作

$this->gallery_path = './images/profileImages/';
于 2013-08-14T13:06:17.557 回答