download helper
- Single Page
Posted 15 August 2012 - 11:20 AM
Posted 15 August 2012 - 18:41 PM
function download_file($file){
$data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
$name = 'myphoto.jpg';
force_download($name, $data);
}
and let's say that you have the function [i]UserIsLoggedIn()[/i] that just returns true or false. So when the user is logged in the file then it will download it normally but if not then it will redirect you to the login page. So this can simply happens like this:
function download_file($file){
if(UserIsLoggedIn()){
if(!file_exists("/path/to/".$file))
{
show_error("Sorry my friend but this file doesn't exist.");
}
$data = file_get_contents("/path/to/".$file); // Read the file's contents
force_download($file, $data);
}
else
{
redirect('admin/login');
}
}
So the URL can easily be like this: [i]example.com/main/download_file/test.pdf[/i] and you can have it as a simple anchor:
<a href="http://example.com/main/download_file/test.pdf">download file here</a>
So if the user is not logged in you will simply redirect him to the login page. If not the user will download the file normally.
Posted 17 August 2012 - 10:55 AM
there is one more help needed... My session is disappearing quicker.. Sometimes as soon as I logged in... can't figure out where's the problem... I'm not using ci_session.. here's my session library.. But the problem is only on xampp.... On server its working fine...but I dun want to take risk
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();
class MY_Session extends CI_Session
{
function __construct()
{
parent::__construct();
}
function userdata($item)
{
if(empty($_SESSION[$item]))
{
return FALSE;
}
else
{
return $_SESSION[$item];
}
}
function set_userdata($items, $value = NULL)
{
if(is_array($items))
{
foreach($items as $item => $value)
{
$_SESSION[$item] = $value;
}
}
else
{
$_SESSION[$items] = $value;
}
}
function unset_userdata($items)
{
if(is_array($items))
{
foreach($items as $item => $value)
{
unset($_SESSION[$item]);
}
}
else
{
unset($_SESSION[$items]);
}
}
function sess_destroy()
{
session_destroy();
}
}
?>
can you provide me idea how to add remember me functionality?? I searched in codeigniter forum but failed to find proper solution..
Posted 23 August 2012 - 01:11 AM
Then, try to modify this: http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime