Location: PHPKode > projects > Brunhilde Media Server > brunhilde/play.php
<?php

### play.php ###
// plays a file upon request
// NOTE: if this was moved to a directory other than the root brunhilde
// directory, you much change the include path to point to global.php
include("global.php");
include("function.php");

// fixes bugs assosiated with extra slashes from rawurlencoding filenames
$play = stripslashes(rawurldecode($play));

// These lines are ESSENTIAL for the brunhilde server remain secure
// They keep a client from entering "../" to gain access to files
// outside of your web tree
if((substr_count($play, "../") > 0) || (substr_count($play, "..\\") > 0)) {
  include("security.php");
  }

// gets a name for the file
$file_name_array = explode("/", $play);
$index = sizeof($file_name_array) - 1;
$file_name = $file_name_array[$index];
$file_name = trim($file_name);

// stores the filepath of the file
$file_path = $MEDIA_DIR[$base][1].$play;
// gets the size of the file
$file_size = filesize($file_path);

// determines the filetype if no variables have been passed
$filter_result = apply_filter($file_name, $file_path);
// sets the $type variable
// case if no filter was chosen
if($filter_result == 0) { $class = 0; }
else {
  $class = $filter_result[0];
  $type = $filter_result[1];
  }
// looks up each mime-type from the global.php type arrays
if($class == 0) { $mime_type = "audio/x-mp3"; }
else if($class == 1) { $mime_type = $AUDIO_TYPE[$type][2]; } // AUDIO
else if($class == 2) { $mime_type = $VIDEO_TYPE[$type][2]; } // VIDEO
else if($class == 3) { $mime_type = $IMAGE_TYPE[$type][2]; } // IMAGES


header("Content-Disposition: filename=$file_name");
header("Accept-Range: bytes");
header("Content-Length: $file_size");
header("Content-Type: $mime_type");

// outputs the contents of the file
readfile($file_path);

exit;

?>
Return current item: Brunhilde Media Server