Jump to content


hiding download source location

  • Please log in to reply
1 reply to this topic

#1 jbadziak

  • Members
  • Pip
  • Newbie
  • 2 posts
  • LocationChicago, IL, USA

Posted 18 September 2006 - 04:37 AM

hello all:

i am trying to write a system that will hide the location of a file download so people can not download the files without being logged into the system.  i found a tutorial to do this on phpfreaks a few years ago, but i tried looking today and was not able to find anything, but that could easily have been because it is under a different name now.

what i'm looking for is something that shows the link as (domain_name)/download.php?id=859, and when someone clicks on the link, the regular "file download" pops up asking the user where they would like to save the file to.

does anyone know where i might be able to find something like this?  i would prefer a tutorial as i have to do a number of other things in addition to this.

any help is greatly apprecaited.

Bow before me, for i am Root
If you play xbox live, please sign up at my clan site. its not complete yet, but we will inform you of all updates. www.sboq.com

#2 Daniel0

  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 18 September 2006 - 06:00 AM

Something like this should do it:
include 'functions.php'; // contains functions to check if the user is logged in
include 'db.php'; // connects to the database

	$id = intval($id);
	$query = mysql_query("SELECT * FROM downloads WHERE id='{$id}' LIMIT 1");
	if(mysql_num_rows($query) <= 0)
		echo "Sorry, no such file.";
	else {
		$file_info = mysql_fetch_assoc($query);
		header("Pragma: public");
		header("Expires: 0");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
		header("Content-Type: application/force-download");
		header("Content-Disposition: attachment; filename=".basename($file_info['path']));
		header("Accept-Ranges: bytes");
		header("Content-Length: ".filesize($file_info['path']));
		header("Content-Description: File Transfer");
else {
	echo "Sorry, you need to be logged in to download this file.";

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users