Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Codeigniter视图中上载和检索图像路径_Php_Codeigniter - Fatal编程技术网

Php 在Codeigniter视图中上载和检索图像路径

Php 在Codeigniter视图中上载和检索图像路径,php,codeigniter,Php,Codeigniter,我对codeigniter是新手。我试着上传一个产品的图片。现在我正在尝试上传每个产品只有一个图像。我已经在我的控制器中完成了这项工作: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Users extends CI_Controller { function __construct() { parent::__construct();

我对codeigniter是新手。我试着上传一个产品的图片。现在我正在尝试上传每个产品只有一个图像。我已经在我的控制器中完成了这项工作:

    <?php defined('BASEPATH') OR exit('No direct script access allowed');
    class Users extends CI_Controller
    {
    function  __construct() {
    parent::__construct();
    $this->load->model('user');
    }

     function add(){
      if($this->input->post('userSubmit')){

        //Check whether user upload picture
        if(!empty($_FILES['picture']['name'])){
            $config['upload_path'] = 'uploads/images/';
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['file_name'] = $_FILES['picture']['name'];

            //Load upload library and initialize configuration
            $this->load->library('upload',$config);
            $this->upload->initialize($config);

            if($this->upload->do_upload('picture')){
                $uploadData = $this->upload->data();
                $picture = $uploadData['file_name'];
            }else{
                $picture = '';
            }
        }else{
            $picture = '';
        }

        //Prepare array of user data
        $userData = array(
            'name' => $this->input->post('name'),
            'email' => $this->input->post('email'),
            'picture' => $picture
        );

        //Pass user data to model
        $insertUserData = $this->user->insert($userData);

        //Storing insertion status message.
        if($insertUserData){
            $this->session->set_flashdata('success_msg', 'User data have been added successfully.');
        }else{
            $this->session->set_flashdata('error_msg', 'Some problems occured, please try again.');
        }
    }
    //Form for adding user data
    $data['data']=$this->user->getdata();
    $this->load->view('show',$data);
}

public function show()
{
    #code
    $data['data']=$this->user->getdata();
    $this->load->view('show',$data);

}
现在的问题是看。我正在尝试动态访问存储的图像,如下所示:

      <!DOCTYPE html>
       <html>
     <head>
   <meta charset="utf-8">
   <title>show</title>
    </head>
       <body>


    <table border='1' cellpadding='4'>
        <tr>
            <td><strong>User_Id</strong></td>
            <td><strong>Name</strong></td>
            <td><strong>Image</strong></td>
            <td><strong>Option</strong></td>
        </tr>
    <?php foreach ($data as $p): ?>
            <tr>
                <td><?php echo $p['id']; ?></td>
                <td><?php echo $p['name']; ?></td>
                <td><img src="../uploads/images/<?php echo $p['picture']; ?>" /> </td>
                <td>
                    <a href="#">View</a> |

                </td>
            </tr>
    <?php endforeach; ?>
    </table>
    <img src="../uploads/images/image-0-02-03-15420e726f6e9c97408cbb86b222586f7efe3b002e588ae6bdcfc3bc1ea1561e-V.jpg" />
     or like this
     <img src="../../uploadsimages/image-0-02-03-15420e726f6e9c97408cbb86b222586f7efe3b002e588ae6bdcfc3bc1ea1561e-V.jpg" />

显示
用户Id
名称
图像
选项
" /> 
|

使用此图像源,图像不会出现。只看到imge crack缩略图。我还尝试手动提供图像的根文件夹,如下所示:

      <!DOCTYPE html>
       <html>
     <head>
   <meta charset="utf-8">
   <title>show</title>
    </head>
       <body>


    <table border='1' cellpadding='4'>
        <tr>
            <td><strong>User_Id</strong></td>
            <td><strong>Name</strong></td>
            <td><strong>Image</strong></td>
            <td><strong>Option</strong></td>
        </tr>
    <?php foreach ($data as $p): ?>
            <tr>
                <td><?php echo $p['id']; ?></td>
                <td><?php echo $p['name']; ?></td>
                <td><img src="../uploads/images/<?php echo $p['picture']; ?>" /> </td>
                <td>
                    <a href="#">View</a> |

                </td>
            </tr>
    <?php endforeach; ?>
    </table>
    <img src="../uploads/images/image-0-02-03-15420e726f6e9c97408cbb86b222586f7efe3b002e588ae6bdcfc3bc1ea1561e-V.jpg" />
     or like this
     <img src="../../uploadsimages/image-0-02-03-15420e726f6e9c97408cbb86b222586f7efe3b002e588ae6bdcfc3bc1ea1561e-V.jpg" />

还是像这样
但这没用。有人能帮我吗?欢迎提供任何建议和建议。谢谢。

试试这个

     <img src="<?php echo base_url('uploads/images/'.$p['picture']); ?>"/>

insted of this line 
<img src="../uploads/images/<?php echo $p['picture']; ?>" />
“/>
代替这条线
" />
还可以正确设置文件夹位置

试试这个

     <img src="<?php echo base_url('uploads/images/'.$p['picture']); ?>"/>

insted of this line 
<img src="../uploads/images/<?php echo $p['picture']; ?>" />
“/>
代替这条线
" />

还可以正确设置文件夹位置。这是一个愚蠢的错误。我让虚拟主机指向根文件夹的index.html。因此,只要指向根文件夹,问题就解决了。

这是一个愚蠢的错误。我让虚拟主机指向根文件夹的index.html。因此,只要指向根文件夹,问题就解决了