EllisLab text mark
Advanced Search
     
Regarding file download
Posted: 19 November 2012 07:51 AM   [ Ignore ]
Joined: 2012-10-02
5 posts
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 viewsI got from internet.

If 
anybody can help....thank uSandip Ray
 
Posted: 21 November 2012 12:34 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-19
324 posts

The path can be a relative or full server path.

Note: The path is relative to your main site index.php file, NOT your controller or view files. CodeIgniter uses a front controller so paths are always relative to the main site index.

file helper

Your using base_url which is probably why its not working

 Signature 

I ask a lot of questions…..........................