Location: PHPKode > projects > MyOWNSpace > MyOWNspace_v8.2/www/classes/flash_mp3_player.23/extras/force_download/getfile.php
<?php

/*

This script forces browsers to download a file rather than loading or streaming
it. It only handles MP3, FLV and JPG files.

You can use it by placing it in the same folder as the SWF file and call this 
script in the link fields of the playlist XML:

	<info>getfile.php?file=mysong.mp3</info>

'file' should equal a filename in the same directory as getfile.php or in a 
sub-directory.

By default the script will only read files in the same directory as itself. To
allow the script to read files in sub-directories too, change the line below
from "$allow_sub_dirs = FALSE;" to "$allow_sub_dirs = TRUE;". Files outside the
script's directory structure can never be retrived because of security concerns.

*/

// Set this to TRUE to allow files in sub-directories relative to the script
// to be retrived
$allow_sub_dirs = FALSE;



///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

$filename = $_GET['file'];
$filename = realpath($filename);

if($allow_sub_dirs) {
  // Only allow reading of files in the current directory or a sub-directory
  $current_dir = dirname(realpath($_SERVER['SCRIPT_FILENAME']));
  if($current_dir != substr(dirname($filename), 0, strlen($current_dir))) {
    echo "Error: The requested file cannot be retrieved for security reasons.";
    die;
  }
} else {
  // Ensure we only look in the current directory for files to read
  $filename = basename("$filename");
}

// Don't read any PHP files, lest we reveal secret source code
if(strToLower(substr($filename,strlen($filename)-3, 3) == 'php')) {
    echo "Error: The requested file cannot be retrieved for security reasons.";
    die;
}

//Make sure the file exists, otherwise send back a 404
if(!file_exists($filename)) {
   header("Status: 404 Not Found");
   ?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL was not found on this server.<P>
</BODY></HTML>
<?PHP
   die();
}

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



// build file headers
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);

$ext = strToLower(substr($filename,strlen($filename)-3, 3));
if ($ext == "mp3" ) { header("Content-Type: audio/x-mp3"); } 
else if ($ext == "jpg") { header("Content-Type: image/jpeg"); }
else if ($ext == "flv") { header("Content-Type: video/flv"); }

header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));


// refer to file and exit
readfile("$filename");
exit();

?>
    
Return current item: MyOWNSpace