[eluser]Unknown[/eluser]
Code:
First I have the following folder structure:
BookShop ----> Project Name
CodeIgniter
images
Now inside the 'images' folder I have a pic file named rr.jpg.
I have the following controller class 'UserController' where I have written the following function :
<?php
class UserController extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('captcha');
$this->load->helper('html');
$this->load->library('form_validation');
$this->load->library('cart');
$this->load->helper('download');
$this->load->model('UserModel','um',TRUE);
}
public function test()
{
$this->load->view('testing');
}
?>
In the views I have written the following within a php webpage which I named 'testing.php' :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
$data = file_get_contents(base_url().'/images/rr.jpg'); // Read the file's contents
$name = 'rr.jpg';
force_download($name, $data);
?>
</body>
</html>
Now in the routes which is within the config folder I have written the following :
$route['tmp']="UserController/test";
Now when I am executing the file,the file is getting downloaded but its not showing the picture within the file.When I am opening it with Fax-Viewer its saying "No preview available" why?.The above code in views, I got from internet.
If anybody can help....thank u. Sandip Ray.