Forum Moderators: coopster
The site I am developing is an industry only site that requires a login and this media will only be viewable to certain authorized users. The media actually doesn't need to be viewable but it needs to be available to download through the browser.
What methods could I use to design a system like this? Server is running apache and site is being built with php/mysql. Any advice will be appreciated.
Thanks!
<?php
session_start();
/*
// Check for permissions here
*/
$path = str_replace('..', '', $_SERVER['QUERY_STRING']);
$fullpath = '/home/site/media/' . $path;
if(!is_file($fullpath)) {
exit('Image not found');
}
header('Content-type:image/jpg');
readfile($fullpath);
?>
// Open file
$file = fopen($path, 'rb');
if(!$file){
// error message
exit;
}$chunk = 1024*1024; //whatever you want
header('Content-type:image/jpg');// Push file
while (!feof($file)) {
echo fread($file, $chunk);
flush();
}
fclose($file);
Much more info at PHP.NET
readfile itself won't read the file to memory but it will end up there anyway if you have output buffering on. You can call ob_end_flush [php.net] just before readfile, to flush and stop buffering.
Andrew