/    Sign up×
Community /Pin to ProfileBookmark

File protection

I currently am storing my .flv files in the cgi-bin directory for protection from being easily stolen. What I want to do is have a script that will allow me to embed files via this method:

Psuedo: <embed src=”flashvideo.php?filename=testfile.flv”></embed>

Then my script will of coarse point to the correct path and allow the flash video player to read the data.

I currently have a script started that does all this and outputs the data with the header() function but doesn’t seem to be doing the trick.

[code=php]
<?PHP
$filename = $_GET[‘filename’];

if(!$filename || empty($filename) || !preg_match(‘/./’,$filename))
{
die(“Invalid filename”);
}

if(isset($filename) && !empty($filename))
{
$dir = “/dir-to-my-files/”;
$file_extension = strtolower(substr(strrchr($filename,”.”),1));

// required for IE, otherwise Content-disposition is ignored
if(ini_get(‘zlib.output_compression’)) ini_set(‘zlib.output_compression’, ‘Off’);

header(“Cache-Control: no-store, no-cache, must-revalidate”); // HTTP/1.1
header(“Cache-Control: post-check=0, pre-check=0”, false);
header(“Pragma: no-cache”); // HTTP/1.0
header(“Content-Type: video/x-flv”);
header(‘Content-Length: ‘ . filesize($dir . $filename));
header(‘Content-Disposition: inline; filename=”‘ . $filename . ‘”‘);
header(“Content-Transfer-Encoding: binaryn”);
readfile($dir . $filename);
exit();
}
?>
[/code]

Any suggestions?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@felgallDec 17.2007 — You will need to add the path to the folder where the file can be found to the front of the filename.

I assume your pseudo <embed> is actually going to be a proper <object> tag as that is the HTML tag for embedding content.
Copy linkTweet thisAlerts:
@sstalderauthorDec 17.2007 — That is the whole point of my script, there is no need to add the path because I declare that as a string in my script to be "hidden" from outside viewers...
Copy linkTweet thisAlerts:
@felgallDec 17.2007 — is $dir = "/dir-to-my-files/"; pointing to your cgi-bin?

is the flashvideo.php in the same folder as where it is being called from?
Copy linkTweet thisAlerts:
@sstalderauthorDec 17.2007 — Yes and yes ?
×

Success!

Help @sstalder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...