| | |
Show secured file
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2006
Posts: 6
Reputation:
Solved Threads: 0
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['filename'];
$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;
}
$filename = $_GET['filename'];
$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;
}
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
[PHP]
error_reporting(E_ALL);
display_errors(1);
[/PHP]
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
[PHP]
error_reporting(E_ALL);
display_errors(1);
[/PHP]
•
•
Join Date: Jul 2006
Posts: 6
Reputation:
Solved Threads: 0
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
[php]
error_reporting(E_ALL);
display_errors(1);
[/php]
•
•
Join Date: Mar 2007
Posts: 1
Reputation:
Solved Threads: 0
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).
![]() |
Similar Threads
- writing to a file (Java)
- can't find file size over 3 megabytes to clean up harddrive (Windows NT / 2000 / XP)
Other Threads in the PHP Forum
- Previous Thread: Dynamic array with update
- Next Thread: New to php and need some help with a guestbook
Views: 1270 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code computing cron curl database date delete directory display domain download dynamic echo email error file files folder form forms function functions google href htaccess html image include indentedsubcategory insert integration ip java javascript joomla jquery limit link load login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





