在codeigniter中存储图像路径

时间:2015-07-09 07:59:54

标签: php codeigniter

你好我写了一个代码,将图像路径上传到数据库但事情是上传真实路径(C:/wamp/www/amref/images/student_profile/childbrah2.jpg)因此当我从数据库中获取路径以显示它给出的图像我链接被破坏的错误。我只想存储(images / student_profile / childbrah2.jpg)。

控制器代码:

$config['upload_path'] = '../images/student_profile/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size'] = "2048000"; // Can be set to particular file size , here it is 2 MB(2048 Kb)
        $config['max_height'] = "768";
        $config['max_width'] ="1024";

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

        if(!$this->upload->do_upload()){

             echo '<h4 style="color: red;">

                    Failure! </h4>

                    <p style="color: red;">'.$this->upload->display_errors().'</p>';



        } else {
            $data_upload_files = $this->upload->data();

            $image = base_url($data_upload_files['full_path']);

1 个答案:

答案 0 :(得分:1)

当然可以。它想要发生。

因为您插入了$config['upload_path'] = '../images/student_profile/';

所以路径为C:/wamp/www/amref/images/student_profile/

如果您将其输入为C:/wamp/www/amref/images/student_profile/,则将无法在您的服务器中使用。您的服务器中的Cz没有分区呼叫C:

所以按原样使用你的路径。

编辑01

<?php

    $old = 'C:/wamp/www/amref';
    $fulpath = $old.'/images/student_profile/';

    echo $fulpath;
相关问题