javascript - Php copy CPU consumption -
i creating site allows users view file via javascript plugin.
to this, , maintain security of file, creating 1 time unique copy of original file, each time javascript plugin accessed.
the original file @ maximum 30mb, how scale multiple users of system? if 100 people create , access copy of file.
you can creating htaccess rewrite refer user php script:
rewriteengine on rewriterule ^download/([^/]+) /lib/download.php?file=$1 [qsa]
this forward request yourdomain.com/download/anyfilehere.mp3?one_time_token=abcdefg
lib/download.php
, set $_get['file']
anyfilehere.mp3
. one_time_token
$_get
parameter forwarded, used [qsa]
.
the download.php
this:
<?php if (!empty($_get['file'])) { if (!empty($_get['one_time_token'])) { if (tokenok($_get['one_time_token'])) { //create function called tokenok download token in eg. database $filename = '/var/www/downloadfolder/' . $_get['file']; if (file_exists($filename)) { expiretoken($_get['one_time_token']); //create function called expiretoken expire token in eg. database readfile($filename); //read file user die(); } else { die('error: file not found'); } } else { die('error: token not ok'); } } else { die('error: token not specified'); } } else { die('error: file not specified'); } ?>
things consider:
- output mime header type specifying content-type of file
- read this php manual entry on
readfile
- limit 1 time token valid in time frame (and notify user of this), instead of allowing downloaded once
- how system react if user cancels download, , therefore can't download again?
- what if download fails? need request new download link?
- if it's streaming mp3 file, make sure seeking works (it won't if seek outside mp3 has streamed to, it'll create new request mp3 file)
Comments
Post a Comment