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!
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.
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.
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: