value('subscriber_online') && check_subscription($session->value('subscriber_online')) && isset($_GET['id']) && is_numeric($_GET['id'])) { // Return a random value function tep_rand($min = null, $max = null) { static $seeded; if (!isset($seeded)) { mt_srand((double)microtime()*1000000); $seeded = true; } if (isset($min) && isset($max)) { if ($min >= $max) { return $min; } else { return mt_rand($min, $max); } } else { return mt_rand(); } } function tep_random_name() { $letters = 'abcdefghijklmnopqrstuvwxyz'; $dirname = '.'; $length = floor(tep_rand(16,20)); for ($i = 1; $i <= $length; $i++) { $q = floor(tep_rand(1,26)); $dirname .= $letters[$q]; } return $dirname; } // Unlinks all subdirectories and files in $dir // Works only on one subdir level, will not recurse function tep_unlink_temp_dir($dir) { $h1 = opendir($dir); while ($subdir = readdir($h1)) { // Ignore non directories if (!is_dir($dir . $subdir)) continue; // Ignore . and .. and CVS if ($subdir == '.' || $subdir == '..' || $subdir == 'CVS') continue; // Loop and unlink files in subdirectory $h2 = opendir($dir . $subdir); while ($file = readdir($h2)) { if ($file == '.' || $file == '..') continue; @unlink($dir . $subdir . '/' . $file); } closedir($h2); @rmdir($dir . $subdir); } closedir($h1); } function tep_redirect($path) { if ( (ENABLE_SSL == true) && (getenv('HTTPS') == 'on') ) { // We are loading an SSL page if (substr($path, 0, strlen(HTTP_SERVER)) == HTTP_SERVER) { // NONSSL path $path = HTTPS_SERVER . substr($path, strlen(HTTP_SERVER)); // Change it to SSL } } header('Location: ' . $path); tep_exit(); } $article = $db->get_sql_row("SELECT * FROM " . DB_PREFIX . "fb_articles WHERE id='" . $_GET['id'] . "'"); // Now send the file with header() magic header("Expires: Mon, 26 Nov 1962 00:00:00 GMT"); header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Content-Type: Application/octet-stream"); header("Content-disposition: attachment; filename=" . $article['path']); define(DOWNLOAD_BY_REDIRECT,false); define(DIR_FS_DOWNLOAD_PUBLIC, 'public/'); define(DIR_FS_DOWNLOAD, 'pdf/'); if (DOWNLOAD_BY_REDIRECT == 'true') { // This will work only on Unix/Linux hosts tep_unlink_temp_dir(DIR_FS_DOWNLOAD_PUBLIC); $tempdir = tep_random_name(); umask(0000); mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777); symlink(DIR_FS_DOWNLOAD . $article['path'], DIR_FS_DOWNLOAD_PUBLIC . $tempdir . '/' . $article['path']); tep_redirect(DIR_WS_DOWNLOAD_PUBLIC . $tempdir . '/' . $article['path']); } else { // This will work on all systems, but will need considerable resources // We could also loop with fread($fp, 4096) to save memory readfile(DIR_FS_DOWNLOAD . $article['path']); } } else {die('Access denied');} ?>