why download.php is better than providing download link directly?

Discussion in 'PHP' started by zozzen, Feb 23, 2008.

  1. #1
    many software download websites prefer to provide a download link with "php" redirection, instead of giving a direct download link.

    Why do they do this? If I also want to let my users download some materials from my website, what should i consider when choosing php method or direct link ?

    Thanks for all advices!
     
    zozzen, Feb 23, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    Several reasons, if the download url changes they don't have to update all the links. Just keep the download_id the same and change the url in the database. Also it cloaks the location of the download file so people can't just scrape the website and take all the download links and build their own site. Plus it lets them track # of downloads etc. If you are running a major software archive, it probably would be worth it to use it. If its just a few files here and there, *shrug* maybe.
     
    shallowink, Feb 23, 2008 IP
  3. zozzen

    zozzen Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks a lot for your detailed explanation. Could you recommend a download management script for me?
     
    zozzen, Feb 23, 2008 IP
  4. asadbashir

    asadbashir Banned

    Messages:
    100
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks for explaining...
     
    asadbashir, Feb 23, 2008 IP
  5. dansgalaxy

    dansgalaxy Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It should be quite easy to make a script for this, just need a db table and a a small script. if you want it basic.
     
    dansgalaxy, Feb 23, 2008 IP
  6. SubmitShop

    SubmitShop Banned

    Messages:
    844
    Likes Received:
    106
    Best Answers:
    0
    Trophy Points:
    0
    #6
    With download.php they track the stat how many download has been done
     
    SubmitShop, Feb 23, 2008 IP
  7. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Here is a version of what I use for an upcoming site.
    
    <?
    	$encval = CleanInput($_GET["ebook"]);
    	$sql = "update ebooks set downloads = downloads + 1 where encrypted = '$encval'";
    	$result = mysql_query($sql);
    	$sql = "select ebook_file FROM ebooks where encrypted = '$encval'";
    	$result = mysql_query($sql);
    	$ebooktotals = mysql_numrows($result);
    	$file_name = "norecipe.pdf";
    	echo mysql_error();
    		while($row = mysql_fetch_array($result))
    			  {
    				$file_name = $row["ebook_file"];
    			  }
    	$filepath = "filez/".$file_name;
    			  
    	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-Type: application/octet-stream");
    	header("Content-Type: application/download");
    	header("Content-Disposition: attachment; filename=".basename($file_name).";");
    	header("Content-Transfer-Encoding: binary");
    	header("Content-Length: ".filesize($filepath));
    	@readfile($filepath);
    ?>
    
    PHP:
     
    imvain2, Feb 23, 2008 IP