开发者

Image display codeigniter fails

I can upload image to the directory but can not disply it on the page. Tried using static html code and codeigniter img() function, both are not working.

Here is my code:

<image src="./applications/views/uploads/image.jpeg" />

and

$this->output->set_header("Content-Type: image/jpeg");
$data['image'] = $this->load->开发者_如何学运维file('../uploads/taurus.jpeg');

the first code shows me broken image the second one shows Unable to load the requested file: taurus.jpeg


<image src="./applications/views/uploads/image.jpeg" />

By default, CodeIgniter denies access to the application folder which is why I suspect this isn't working.

$this->output->set_header("Content-Type: image/jpeg");
$data['image'] = $this->load->file('../uploads/taurus.jpeg');

I suspect this isn't working because your path is incorrect. The path is relative to the index.php file in the root of your application, not the file this code is in. Secondly, $this->load->file() sends to file contents to the browser so this wouldn't work anyway.

A solution would be to move your uploads folder to a web accessible location. For example, place the uploads folder into the root of your application - the same folder as your index.php file. Then you can display your image like this:

<image src="/uploads/image.jpeg" />


Just get rid of the dot (.) in the URL so your src url reads: "/applications/views/uploads/image.jpeg"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜