Welcome Guest, Not a member yet? Register   Sign In
Filedownload for members only
#1

[eluser]a.rishwan[/eluser]
Hi,

I have used codeigniter for various projects so far. And I am just loving CI so far.

Anyways, I am about to start work on a little hobby project of my own. What I am trying to achieve is create a webapp, where users can login, and they will be show a list of files which only they can access. And they can download if they wish to.

I know I could serve a view with the said links loaded in them and check if the member is logged in or not.

BUT, I cannot seem to prohibit someone from downloading said files or single file, if they just type in the direct URL to the file itself.

How do I avoid that from happening? I think the behaviour rapidshare or other hosting services achieves this somehow. How do I go about setting it up?

Thanks in Advance.
#2

[eluser]ηυмвєяσηє[/eluser]
http://php.net/manual/en/function.header.php
#3

[eluser]a.rishwan[/eluser]
HI there ηυмвєяσηє, could you explain how I can apply this?
#4

[eluser]ηυмвєяσηє[/eluser]
u can use something like this.

Code:
$file_path = DOWNLOAD_FOLDER . $file_name);
    if (file_exists($file_path)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file_path));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file_path));
        ob_clean();
        flush();
        readfile($file_path);
      }

filename would comes from a database or directlink. and control the sessions etc. its up to you

jfshdff.com/download.php?download_id=34
jfshdff.com/download.php?download_file=adweasde_test.zip




Theme © iAndrew 2016 - Forum software by © MyBB