我无法显示保存在MYSQL数据库中的图像 以下是我上传文件的视图代码
<?php echo form_open_multipart('Welcome/do_upload');?>
<input name="file" size="40" type="file" />
<input type="submit" value="Upload" />
这是我的控制器文件
public function do_upload()
{
$this->output->enable_profiler(TRUE);
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '3000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('file'))
{
$error = array('error' => $this->upload->display_errors());
echo "<pre>";
print_r($this->input->post());
print_r($error);
}
else
{
$data = array('upload_data' => $this->upload->data('file'));
echo "Upload";
$this->Blog->insert_images($this->upload->data());
$data = array('upload_data' => $this->upload->data());
}
}
这是我的模型文件 此文件首先插入图像,然后显示数据库中的所有图像
public function insert_images($image_data = array()){
$data = array(
'i_id' => "NULL",
'i_s' => $image_data['full_path']
);
$img=$this->db->get('images')->result();
foreach($img as $i){
?>
<img src="<?php echo $i->i_s?>">
<?php
}
}
任何帮助都将受到高度赞赏
答案 0 :(得分:1)
问题是保存数据库中的路径
$data = array(
'i_id' => "NULL",
'i_s' => $image_data['full_path']
);
通过此
替换此代码$data = array(
'i_id' => "NULL",
'i_s' => $image_data['file_name']
);
并显示来自数据库的图像编写此代码
<?php foreach($im as $imd){?>
<img src="<?php echo base_url('uploads/'.$imd->i_s);?>">
<?php }?>
答案 1 :(得分:0)
You are not supposed to store file absolute path. You should store relative path of image in database. Relative to
private void button2_Click(object sender, EventArgs e)
{
SqlCommand rcmd = new SqlCommand("SELECT ID, Column1, Column2 FROM [TEST].[dbo].[Table_1] where ID=@ID", connection);
rcmd.Parameters.AddWithValue("@ID", textBox3.Text);
connection.Open();
SqlDataReader reader = rcmd.ExecuteReader();
while (reader.Read())
{
textBox4.Text = reader["Column1"].ToString();
textBox5.Text = reader["Column2"].ToString();
}
connection.Close();
}
For example: if your settings are
FCPATH
, stored string in DB should be something like
$config['base_url'] = 'http://localhost/site/';
When you want to see it in browser, you would call
img.jpg