Generating unique download link to download once only

回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Generating unique download link to download once only

文章 yehlu »

https://stackoverflow.com/questions/188 ... -once-only

代碼: 選擇全部

$fileid = $_REQUEST['file'];
$file = file_location($fileid); // you'd write this function somehow
if ($file === null) die("The file doesn't exist");
$allowed = check_permissions_for($file, $fileid) // again, write this
// the previous line would allow you to implement arbitrary checks on the file
if ($allowed) {
  mark_downloaded($fileid, $file); // so you mark it as downloaded if it's single-use
  header("Content-Type: application/octet-stream"); // downloadable file
  echo file_get_contents($file);
  return 0; // running a return 0; from outside any function ends the script
} else
  die("You're not allowed to download this file");
回覆文章

回到「PHP」