I have a folder called _secure in which I have a .htaccess file that denies all access to the _secure folder. Within the _secure folder I also have a swf file. I'm using PHP to retrieve the secured swf file and show it if the user is logged in. For some reason my code bellow doen't seem to work. I would appreciate any help.

$filename = $_GET;
$dir = '_secure/';

if ( user_logged_in() ) {
download_file( $filename, $dir );
} else {
header("HTTP/1.1 404 Not Found"); // dead end
}

function download_file( $fname, $path) {
$fpath = $path.$fname; // absolute path to file
$fsize = filesize( $fpath ); // size of file

header('Content-Type: application/x-shockwave-flash');
$content = file_get_contents($fpath);
echo $content;
}

Recommended Answers

All 6 Replies

any erros outputted?
If you are dnying all access to the "secure" are there any entries in the apache error logs?

I would wrap the file_get_contents() call in an if statement, this way you can see where the program fails. maybe try echoing the path fname, fpath variables out, see what they are set to.
Also add these to the top of your file

error_reporting(E_ALL);
display_errors(1);

I got it to work. But since it is a swf 5mb file it takes a while to get it. How can I fix this?

any erros outputted?
If you are dnying all access to the "secure" are there any entries in the apache error logs?

I would wrap the file_get_contents() call in an if statement, this way you can see where the program fails. maybe try echoing the path fname, fpath variables out, see what they are set to.
Also add these to the top of your file

error_reporting(E_ALL);
display_errors(1);

To be slightly unhelpful but honest, get a faster server or optimise your web server. There is not much else you can do. Apart from streaming the flash flie to the user so that it starts playing before the whole file has finished downloading it.

You can try to increase the maximum execution time via set_time_limit() function or via php.ini if it is disabled (it is 30 seconds by default).

Yes, that's what I thought streaming the file would be the best option for me. I gotta work on that then. If you can help on that I would really appreciate.

You need to learn about making a flash preloader. It won't really speed up the loading time, but will give your visitor an indication that something is happening and the progress.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.