Posts

Showing posts from 2014

PHP Force Download – Keep Track of What’s Going Down

Thanks to my Friend Jainesh to suggest A force-download script can give you more control over a file download than you would have providing a direct link. Using a force-download script, you can: Validate that a person is logged in Increment a counter in a text file Connect to your database and log IP information, increment a counter, and so on. The code itself is pretty basic: // grab the requested file's name $file_name = $_GET [ 'file' ] ; // make sure it's a file before doing anything! if ( is_file ( $file_name ) ) { /* Do any processing you'd like here: 1. Increment a counter 2. Do something with the DB 3. Check user permissions 4. Anything you want! */ // required for IE if ( ini_get ( 'zlib.output_compression' ) ) { ini_set ( 'zlib.output_compression' , 'Off' ) ; } // get the file mime type using the file extension switch ( strtolower ( substr ( strrchr ( $file_name , '.' ) , ...