Welcome Guest, Not a member yet? Register   Sign In
Is there any way to download a image when it is clicked?

[quote author="cereal" date="1293213988"]Or you can create a controller "download" like this:


class Download extends Controller {

    function Download()
        $this->load->helper(array('url', 'download'));
    function image()
    $data = file_get_contents($this->input->server('DOCUMENT_ROOT') . 'images/' . $this->uri->segment(3));
        $name = $this->uri->segment(3);
        force_download($name, $data);

To download just call: http://your.server/download/image/name_of_file.jpg

This way you can add a session check to prevent direct linking, keep track of downloads, you can hide the real path and you can use an .htaccess file to prevent downloads from the images/ directory. Bye Smile[/quote]

I tried but I'm getting this error:

ErrorException [ Warning ]: file_get_contents(http://192.168.1/ci/uploads/galeriasFotos/image_jpg) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
The image is in /uploads/galeriasFotos/

I can see that the problem is that the controller change image.jpg to image_jpg.
Why is that?
<a href="http://192.168.1/ci/download/image/image.jpg"></a>

Messages In This Thread
Is there any way to download a image when it is clicked? - by El Forum - 12-24-2010, 06:33 AM

Theme © iAndrew 2016 - Forum software by © MyBB