function download_pub_file()
{
$url = check_url($_GET['file']);
$pub_id = $_GET['pub_id'];
$first_last = $_GET['first_last'];
$cookie_name = "pub_".$pub_id;
/**
* Step-3: check if the url is valid or not
*/
if (is_valid_file_url(htmlspecialchars($url)) && $first_last=='ok' && !isset($_COOKIE[$cookie_name])) {
/**
* Step-4: update counter data (only if the URL is valid and file exists)
*/
update_num_of_download($pub_id);
setcookie($cookie_name, "downloaded", time()+9000);
}
/**
* Step-5: redirect to the original URL of the file
*/
header('Location: ' . $url);
exit;
}
function update_num_of_download($pub_id)
{
$sql_query = sprintf("INSERT INTO tbldownloadcount VALUES (%d,1) ON DUPLICATE KEY UPDATE download_times=download_times+1;", $pub_id);
db_pub_query($sql_query);
}
function is_valid_file_url($url)
{
// replace space characters in the URL with '%20' to support file name
// with space characters
$url = preg_replace('/\s/', '%20', $url);
if (!valid_url($url, true)) {
return false;
}
if (!url_exists($url)) {
return false;
}
return true; // it seems that the file URL is valid
}
function url_exists($url)
{
if (@fopen($url,"r")) {
return true;
} else {
return false;
}
}
?>
Pana - a mission not impossible: success story in rubber garden establishment
Writer
World Agroforestry Centre-ICRAF, SEA Regional Office
Year
2008
Publisher
World Agroforestry Centre - ICRAF, SEA Regional Office
City
Bogor, Indonesia
Duration
10 minutes
Media Type (CD / Tape)
DVD
Call Number
A10028-08
Price
Rp. 20000
ODC $5
DC $3
GRP 2 : Maximizing on-farm productivity of trees and agroforestry systems GRP 5 : Improving the ability of farmers, ecosystems & governments to cope with climate change