Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
537 views
in Plugins by
Hi friends ,

My website users downloading all data from site

" deducting my bandwidth"  

How can set only register user can download file attachment

1 Answer

+1 vote
by
Here is the code snippet that i implemented version Q2A 1.6.3

Created a new download.php under qa-include

$userid=qa_get_logged_in_userid();
    error_log("Logged in User " . $userid);    
    
    if( $userid){
        $file = "dl/".$requestparts[1];
        
        if (file_exists($file)) {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename='.basename($file));
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file));
            readfile($file);
            
        }
    } else {
        $qa_content=qa_content_prepare();
        $qa_content['error']=qa_insert_login_links(qa_lang_html('question/download_must_login'), qa_request(), isset($followpostid) ? array('follow' => $followpostid) : null);
        return $qa_content;
    }

 

In the qa-page.php routing add a mapping for download to above file
...