Welcome Guest, Not a member yet? Register   Sign In
Regarding file download
#1

[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.
#2

[eluser]Otemu[/eluser]
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




Theme © iAndrew 2016 - Forum software by © MyBB