I am working on a project where the user would be able to buy media files. after the payment is processed I would like to allow them to download the file. I guess it is safe to say that I should have a temporary link to the files. one that is linked to the IP of the user and perhaps a timestamp? the problem is I dont know where to start with that. First of all. is this the way to do it? if so..how do I proceed using php. ( i guess I dont need the exact script just hints on how to do it although if there is an existing script I would not mind) thank you.
3条回答 默认 最新
dongshao2967 2010-08-26 13:33关注Since you are going to handle the file in PHP you might aswell use a login to check if the user has purchased the file, other than that the code should look a little like this:
header('Content-Type: application/force-download'); $file = new File(intval($_GET['id'])); $fileLocation = dirname(__FILE__) . "/../../upload/fileArchive/" . $file->id . "." . $file->type; header('Content-Length:' . filesize($fileLocation)); header("Content-Disposition: inline; filename=\"".$file->name."\""); $filePointer = fopen($fileLocation,"rb"); fpassthru($filePointer);Taken from production and tested
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报