Пример #1
0
<?php

require_once '../Browser/checkaddr.php';
$file = str_replace("\\'", "'", $_GET['file']);
$len = filesize($file);
header("Content-type: " . mime_content_type($file) . "\r\n");
header("Content-Length: {$len};\r\n");
header('Content-disposition: attachment; filename="' . basename($file) . '"' . "\r\n");
header("Cache-Control: no-cache\r\n");
header("Pragma: hack\r\n");
header("Content-Transfer-Encoding: binary\r\n");
if (isset($_GET['start'])) {
    streamFile($file, $_GET['start']);
} else {
    streamFile($file);
}
Пример #2
0
<?php

require_once '../Browser/checkaddr.php';
// Read the filename from the URL
$filename = $tmpfolder . '/' . str_replace('/flv2/streamflv.php/', '', $_SERVER['REQUEST_URI']) . '.flv';
// Load the streaming FLV starting position if supplied, to support seeking
if (isset($_GET['start'])) {
    $start = $_GET['start'];
} else {
    $start = 0;
}
// Set headers to block caching and browsers from displaying the flv directly
header("Content-type: application/octet-stream\r\n");
header('Content-disposition: attachment; filename="' . basename($filename) . '"' . "\r\n");
header("Cache-Control: no-cache\r\n");
header("Pragma: hack\r\n");
header("Content-Transfer-Encoding: binary\r\n");
// If our file is less than 16kb, we're not going to be able to stream it
if (filesize($filename) < 1024 * 16) {
    header("HTTP/1.0 505 Internal server error");
    return;
    // If the client has requests a partial file, return the correct HTTP header so the player doesn't freak out
} elseif ($start != 0) {
    header('HTTP/1.0 206 Partial Content');
    // Everything worked! :O
} else {
    header('HTTP/1.0 200 OK');
}
// Dump the file
streamFile($filename, $start);
Пример #3
0
<?php

require_once '../Browser/checkaddr.php';
$file = str_replace("\\'", "'", $_GET['file']);
if (isset($_GET['start'])) {
    streamFile($file, $_GET['start']);
} else {
    readfile($file);
}
Пример #4
0
function streamFile($filename, $start = 0)
{
    // Open the file and setup our first pass
    $cur = $start;
    $file = fopen($filename, 'rb');
    $end = filesize($filename);
    $oldchunk = '';
    // Loop until we've read up to the filesize of when we started
    while ($cur < $end - 8) {
        $out = '';
        // Seek to the supplied start value or to the end of the last pass
        fseek($file, $cur, 0);
        // Read a 16kb chunk from the current location
        $out = @fread($file, 1024 * 16);
        // If theres less than 16kb remaining in the file, just read that much
        if ($out == '' && $end - $cur < 1024 * 16) {
            $out = @fread($file, $end - $cur);
        }
        $len = mb_strlen($out);
        // If fopen has returned an EOF flag, we don't want the last byte (the EOF marker)
        if (feof($file)) {
            $len = $len - 8;
        }
        $oldchunk = mb_substr($out, $len, 8);
        // Trim the output to the size we expect
        $out = mb_substr($out, 0, $len);
        // Output the chunk
        print $out;
        // Increment the current position by the amount of data read
        $cur += $len;
    }
    sleep(1);
    // Compare the filesize to when we started
    clearstatcache();
    if (filesize($filename) > $end) {
        // If the file is has grown, it's still being generated, so setup for another pass
        $end = filesize($filename);
        // Throw away the old file handle and cleanup all traces of it
        fclose($file);
        unset($file);
        clearstatcache();
        // Start the next pass from the current position
        streamFile($filename, $cur);
    } else {
        print $oldchunk;
    }
}
Пример #5
0
/**
 * Sends the actual media file
 * and possibly resamples it.
 * 
 * 
 * @author Ben Dodson
 * @version 11/11/04
 * @since 11/11/04
 */
function sendMedia($path, $name, $resample = false, $download = false)
{
    // Let's get the extension from the file
    $extArr = explode(".", $path);
    $ext = $extArr[count($extArr) - 1];
    // Now let's fix up the name
    if (substr($name, 0 - strlen($ext) - 1) != "." . $ext) {
        $name .= "." . $ext;
    }
    if ($resample != "") {
        $ext = false;
    }
    // TODO: resample.
    // probably make a different streamFile (streamResampled)
    streamFile($path, $name, false, $resample, $download, true, $ext);
}
Пример #6
0
function stream()
{
    global $cfg, $db;
    $track_id = get('track_id');
    $stream_id = (int) get('stream_id');
    $sid = get('sid');
    $hash = get('hash');
    if ($stream_id != -1 && isset($cfg['encode_extension'][$stream_id]) == false) {
        header('HTTP/1.1 400 Bad Request');
        exit;
    }
    if ($hash) {
        authenticateStream();
    } else {
        authenticateShareStream();
    }
    $query = mysql_query('SELECT
		LOWER(SUBSTRING_INDEX(relative_file, ".", -1)) AS extension,
		track.artist, title, album, album.year, disc, discs, number,
		relative_file, mime_type, miliseconds, filesize, filemtime, audio_bitrate
		FROM track, album
		WHERE track_id = "' . mysql_real_escape_string($track_id) . '"
		AND track.album_id = album.album_id');
    $track = mysql_fetch_assoc($query);
    $file = $cfg['media_dir'] . $track['relative_file'];
    if (sourceFile($track['extension'], $track['audio_bitrate'], $stream_id)) {
        // Stream from source
        streamFile($file, $track['mime_type']);
    } elseif ($cache = cacheGetFile($track_id, $stream_id)) {
        // Stream from cache
        cacheUpdateTag($track_id, $stream_id, $cache);
        streamFile($cache, $cfg['encode_mime_type'][$stream_id]);
    } else {
        // Real time transcode stream
        ini_set('zlib.output_compression', 'off');
        ini_set('max_execution_time', 0);
        if (file_exists(NJB_HOME_DIR . '-')) {
            @unlink(NJB_HOME_DIR . '-');
        }
        $cmd = $cfg['decode_stdout'][$track['extension']] . ' | ' . $cfg['encode_stdout'][$stream_id];
        $cmd = str_replace('%source', escapeCmdArg($file), $cmd);
        header('Accept-Ranges: none');
        header('Content-Type: ' . $cfg['encode_mime_type'][$stream_id]);
        if (@passthru($cmd) == false) {
            header('HTTP/1.1 500 Internal Server Error');
            exit;
        }
    }
}
#**********************************************************
#<1>set target path for storing photo uploads on the server
$photo_upload_path = "./upload/";
$photo_upload_path = $photo_upload_path . basename($_FILES['uploadedfile']['name']);
#<2>set target path for storing result on the server
$processed_photo_output_path = "./output/processed_";
$processed_photo_output_path = $processed_photo_output_path . basename($_FILES['uploadedfile']['name']);
$downloadFileName = 'processed_' . basename($_FILES['uploadedfile']['name']);
#<3>modify maximum allowable file size to 10MB and timeout to 300s
ini_set('upload_max_filesize', '10M');
ini_set('post_max_size', '10M');
ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);
#<4>Get and stored uploaded photos on the server
if (copy($_FILES['uploadedfile']['tmp_name'], $photo_upload_path)) {
    #<5> execute matlab image processing algorithm
    #example: Compute and display SIFT features using VLFeat and Matlab
    #$command = "/Applications/MATLAB_R2013a_Student.app/bin/matlab -nojvm -nodesktop -nodisplay -r \"computeSIFT('$photo_upload_path','$processed_photo_output_path');exit\"";
    #$command = "/Applications/MATLAB_R2013a_Student.app/bin/matlab -r \"computeLayout('$photo_upload_path','$processed_photo_output_path');exit\"";
    $command = "/Applications/MATLAB_R2014a.app/bin/matlab -r \"computeLayout('{$photo_upload_path}','{$processed_photo_output_path}');exit\"";
    exec($command);
    #<6>stream processed photo to the client
    streamFile($processed_photo_output_path, $downloadFileName, "application/octet-stream");
} else {
    echo "There was an error uploading the file to {$photo_upload_path} !";
}
?>



Пример #8
0
function downloadTrack($track_id)
{
    global $cfg, $db;
    authenticate('access_download', true);
    $download_id = (int) get('download_id');
    if ($download_id != -1 && isset($cfg['encode_extension'][$download_id]) == false) {
        message(__FILE__, __LINE__, 'error', '[b]Unsupported input value for[/b][br]download_id');
    }
    $query = mysql_query('SELECT
		LOWER(SUBSTRING_INDEX(relative_file, ".", -1)) AS extension,
		relative_file,
		mime_type,
		miliseconds,
		filesize,
		audio_bitrate
		FROM track
		WHERE track_id = "' . mysql_real_escape_string($track_id) . '"');
    $track = mysql_fetch_assoc($query);
    if (sourceFile($track['extension'], $track['audio_bitrate'], $download_id)) {
        // Download source file
        $file = $cfg['media_dir'] . $track['relative_file'];
        $pathinfo = pathinfo($file);
        $filename = $pathinfo['basename'];
        $filename = downloadFilename($filename);
        streamFile($file, $track['mime_type'], 'attachment', $filename);
        return true;
    } elseif ($file = cacheGetFile($track_id, $download_id)) {
        // Download from cache
        $pathinfo = pathinfo($track['relative_file']);
        $filename = $pathinfo['filename'] . '.' . $cfg['encode_extension'][$download_id];
        $filename = downloadFilename($filename);
        cacheUpdateTag($track_id, $download_id, $file);
        streamFile($file, $cfg['encode_mime_type'][$download_id], 'attachment', $filename);
        return true;
    }
    ini_set('max_execution_time', 0);
    $query = mysql_query('SELECT album.artist_alphabetic, album.album, album.album_id
		FROM album, track
		WHERE track.album_id = album.album_id
		AND track_id = "' . mysql_real_escape_string($track_id) . '"');
    $album = mysql_fetch_assoc($query);
    if ($album == false) {
        message(__FILE__, __LINE__, 'error', '[b]Error[/b][br]track_id not found in database');
    }
    // formattedNavigator
    $nav = array();
    $nav['name'][] = 'Media';
    $nav['url'][] = 'index.php';
    $nav['name'][] = $album['artist_alphabetic'];
    $nav['url'][] = 'index.php?action=view2&amp;artist=' . rawurlencode($album['artist_alphabetic']);
    $nav['name'][] = $album['album'];
    $nav['url'][] = 'index.php?action=view3&amp;album_id=' . $album['album_id'];
    $nav['name'][] = 'Download track';
    require_once 'include/header.inc.php';
    ?>
<table cellspacing="0" cellpadding="0" class="border">
<tr class="header">
	<td class="space"></td>
	<td>Transcode to <?php 
    echo html($cfg['encode_name'][$download_id]);
    ?>
</td>
	<td class="textspace"></td>
	<td></td>
	<td class="textspace"></td>
	<td></td>
	<td class="space"></td>
</tr>
<tr class="line"><td colspan="7"></td></tr>
<?php 
    $query = mysql_query('SELECT title, artist FROM track WHERE track_id = "' . mysql_real_escape_string($track_id) . '"');
    $track = mysql_fetch_assoc($query);
    ?>
<tr class="odd">
	<td></td>
	<td><?php 
    echo html($track['artist']);
    ?>
</td>
	<td></td>
	<td><?php 
    echo html($track['title']);
    ?>
</td>
	<td></td>
	<td><span id="status"><img src="<?php 
    echo $cfg['img'];
    ?>
small_animated_progress.gif" alt="" class="small"></span></td>
	<td></td>
</tr>
<tr class="line"><td colspan="7"></td></tr>
<tr class="header">
	<td></td>
	<td colspan="5">Download</td>
	<td></td>
</tr>
<tr class="line"><td colspan="7"></td></tr>
<tr class="odd">
	<td></td>
	<td colspan="5"><span id="text">Prepare file</span></td>
	<td></td>
</tr>
</table>
<?php 
    $cfg['footer'] = 'dynamic';
    require 'include/footer.inc.php';
    $file = transcode($track_id, $download_id);
    $download_url = NJB_HOME_URL . 'download.php?action=downloadTrack&amp;track_id=' . rawurlencode($track_id) . '&amp;download_id=' . $download_id;
    $download_url .= '&amp;timestamp=' . dechex(time());
    echo '<script type="text/javascript">document.getElementById(\'status\').innerHTML=\'<img src="' . $cfg['img'] . 'small_check.png" alt="" class="small">\';</script>' . "\n";
    echo '<script type="text/javascript">document.getElementById(\'text\').innerHTML=\'<a href="' . $download_url . '"><img src="' . $cfg['img'] . 'small_download.png" alt="" class="small space">Download ' . $cfg['encode_extension'][$cfg['download_id']] . ' file (' . formattedSize(filesize($file)) . ')<\\/a>\';</script>' . "\n";
    echo '<iframe src="' . $download_url . '" width="0" height="0" scrolling="no" frameborder="0"></iframe>' . "\n";
    $cfg['footer'] = 'close';
    require 'include/footer.inc.php';
}
Пример #9
0
$file = str_replace("\\'", "'", $_GET['file']);
if (isset($_GET['imdbid'])) {
    $result = mysql_query("SELECT Filename, Part FROM imdbfiles WHERE imdbid=" . $_GET['imdbid']);
    if (mysql_num_rows($result) > 1) {
        list($name, $parts) = mysql_fetch_array(mysql_query("SELECT DISTINCT imdb.Name, MAX(imdbfiles.part) FROM imdb, imdbfiles WHERE imdb.id=imdbfiles.imdbid AND imdb.id=" . $_GET['imdbid'] . " GROUP BY imdb.Name"));
        echo "<BR/><BR/><BR/><CENTER>";
        while (list($filename, $part) = @mysql_fetch_array($result)) {
            $file = '/opt/filestore/Movies/' . $filename;
            echo "<A HREF='download.php?file=" . urlencode($file) . "'>{$name} - Part {$part} of {$parts}</A><BR/><BR/>";
        }
        die;
    } else {
        list($filename, $part) = @mysql_fetch_array($result);
        if ($part != 0) {
            die('Database query failed');
        }
        $file = '/opt/filestore/Movies/' . $filename;
    }
}
$testfile = '-' . $file;
if (strpos($testfile, '/opt/') + strpos($testfile, '/mnt/') + strpos($testfile, '/tmp/') == 0) {
    die('F**k off hacker');
}
header('Content-disposition: attachment; filename="' . basename($file) . '"');
header("Cache-Control:");
header("Content-Type: application/octet-stream");
if ($online) {
    streamFile($file, 0, 850);
} else {
    streamFile($file, 0, 800);
}
Пример #10
0
function streamFile($filename, $start = 0, $speedlimit = 0)
{
    // Close any open session handles
    if (isset($_SESSION['username'])) {
        session_write_close();
    }
    // Open the file and setup our first pass
    $cur = $start;
    if ($speedlimit) {
        $slicesize = 1024 * ($speedlimit + $speedlimit * 0.0098);
    } else {
        $slicesize = 1024 * 16;
    }
    // 16kb Slices
    $file = fopen($filename, 'r');
    $end = filesize($filename);
    if ($end <= 1) {
        $time = microtime(true);
        $out = '';
        // Seek to the supplied start value or to the end of the last pass
        fseek($file, $cur, SEEK_SET);
        // Read a 16kb chunk from the current location
        while (!feof($file)) {
            print @fread($file, $slicesize);
            // If a speed limit is set
            if ($speedlimit) {
                // Sleep for 1 seconds
                $diff = microtime(true) - $time;
                if ($diff <= 0 || $diff >= 800000) {
                    $diff = 0;
                }
                usleep(1000000 - $diff);
            }
        }
    } else {
        $oldchunk = '';
        // Loop until we've read up to the filesize of when we started
        while ($cur < $end - 8) {
            $time = microtime(true);
            $out = '';
            // Seek to the supplied start value or to the end of the last pass
            fseek($file, $cur, SEEK_SET);
            // If theres less than 16kb remaining in the file, just read that much
            if ($out == '' && $end - $cur < $slicesize) {
                $out = @fread($file, $end - $cur);
            } else {
                // Read a 16kb chunk from the current location
                $out = @fread($file, $slicesize);
            }
            $len = mb_strlen($out);
            // If fopen has returned an EOF flag, we don't want the last byte (the EOF marker)
            if (feof($file)) {
                $len = $len - 8;
            }
            $oldchunk = mb_substr($out, $len, 8);
            // Trim the output to the size we expect
            $out = mb_substr($out, 0, $len);
            // Output the chunk
            print $out;
            // Increment the current position by the amount of data read
            $cur += $len;
            // If a speed limit is set
            if ($speedlimit) {
                // Sleep for 1 seconds
                $diff = microtime(true) - $time;
                if ($diff <= 0 || $diff >= 800000) {
                    $diff = 0;
                }
                usleep(1000000 - $diff);
            }
        }
        sleep(1);
        // Compare the filesize to when we started
        clearstatcache();
        // If the file is has grown, it's still being generated, so setup for another pass
        if (filesize($filename) > $end) {
            // Throw away the old file handle and cleanup all traces of it
            fclose($file);
            clearstatcache();
            // Start the next pass from the current position
            streamFile($filename, $cur, $speedlimit);
        } else {
            print $oldchunk;
        }
    }
}
Пример #11
0
/**
 * The general resample/transcode function
 * 
 * @author Ross Carlson, Ben Dodson
 * @version 05.25.05
 * @since 05.25.05
 * @param $file The file that we are resampling/transcoding
 * @param $name The name of the stream
 * @param $resample The rate to resample/transcode to
 */
function SERVICE_RESAMPLE($file, $name, $resample)
{
    global $path_to_lame, $path_to_flac, $path_to_mpc, $path_to_wavunpack, $path_to_oggdec, $lame_cmd, $path_to_wmadec, $path_to_shn, $path_to_mplayer, $mplayer_opts, $path_to_faad, $path_to_macpipe, $path_to_ofr;
    $jzSERVICES = new jzServices();
    $jzSERVICES->loadStandardServices();
    // Now let's add the proper options to the lame command
    $lame_cmd .= $resample . ' -f -';
    //Now let's figure out the file type
    $extArr = explode(".", $file);
    $ext = $extArr[count($extArr) - 1];
    // Now if we're on Windows we need to change the slashes for the command line
    if (stristr($_ENV['OS'], "win")) {
        $file = str_replace("/", "\\", $file);
    }
    switch ($ext) {
        case "mp3":
            $meta = $jzSERVICES->getTagData($file);
            if ($meta['bitrate'] <= $resample) {
                header("Content-Type: audio/x-mp3");
                streamFile($file, $meta['artist'] . $meta['title'], $resample);
                exit;
            } else {
                $command = $path_to_lame . " --mp3input -S --silent --quiet --lowpass 12.0 --resample 22.05 -m j -b " . $resample . ' - < "' . $file . '" -';
            }
            break;
        case "flac":
            $command = $path_to_flac . ' -d -c --totally-silent "' . $file . '" | ' . $lame_cmd;
            break;
        case "mpc":
            $command = $path_to_mpc . ' --wav "' . $file . '" | ' . $lame_cmd;
            break;
        case "wv":
            $command = $path_to_wavunpack . ' -q "' . $file . '" - | ' . $lame_cmd;
            break;
        case "ogg":
            // Ok, are they using oggdec or ogg123?
            if (stristr($path_to_oggdec, "oggdec")) {
                //$command = $path_to_oggdec. ' --stdout "'. $file. '" | '. $lame_cmd;
                $command = $path_to_oggdec . ' -Q "' . $file . '" -o - | ' . $lame_cmd;
            } else {
                $command = $path_to_oggdec . ' --skip 1 -q -d wav -f - "' . $file . '" | ' . $lame_cmd;
            }
            break;
        case "wav":
            $command = $path_to_lame . " -S --silent --quiet --lowpass 12.0 --resample 22.05 -m j -b " . $resample . ' - < "' . $file . '" -';
            break;
        case "shn":
            if (stristr($_ENV['OS'], "win")) {
                $command = $path_to_shn . ' -x "' . $file . '" - | ' . str_replace(" -S --silent", " -x -S --silent", $lame_cmd);
            } else {
                $command = $path_to_shn . ' -x "' . $file . '" - | ' . $lame_cmd;
            }
            break;
        case "wma":
            $command = $path_to_wmadec . ' -w "' . $file . '" | ' . $lame_cmd;
            break;
        case "ape":
            $command = $path_to_macpipe . ' "' . $file . '" - -d | ' . $lame_cmd;
            break;
        case "ofr":
            $command = $path_to_ofr . ' --decode --silent "' . $file . '" --output - | ' . str_replace(" -S --silent", " -x -S --silent", $lame_cmd);
            break;
        case "ra":
        case "ram":
        case "rm":
        case "m4a":
            if (stristr($_ENV['OS'], "win")) {
                $command = $path_to_faad . ' -w "' . $file . '" | ' . str_replace(" -S --silent", " -x -S --silent", $lame_cmd);
            } else {
                $command = $path_to_mplayer . ' ' . $mplayer_opts . ' "' . $file . '" | ' . $lame_cmd;
            }
            break;
        default:
            exit;
            break;
    }
    // Let's log the command we just passed
    writeLogData("resample-command", $command);
    // Now let's send the resampled data
    sendResampledFile($command, $name);
    exit;
}
Пример #12
0
/**
 * Sends the actual media file
 * and possibly resamples it.
 * 
 * 
 * @author Ben Dodson
 * @version 11/11/04
 * @since 11/11/04
 */
function sendMedia($path, $name, $resample = false, $download = false)
{
    // Let's get the extension from the file
    $extArr = explode(".", $path);
    $ext = $extArr[count($extArr) - 1];
    // Now let's fix up the name
    if (substr($name, 0 - strlen($ext) - 1) != "." . $ext) {
        $name .= "." . $ext;
    }
    // First are we resampling?
    // If so no header here
    if ($resample == "") {
        sendContentType($ext);
    }
    // TODO: resample.
    // probably make a different streamFile (streamResampled)
    streamFile($path, $name, false, $resample, $download);
}
Пример #13
0
<?php

$secure = 1;
require_once 'config.php';
$file = str_replace("\\'", "'", $_GET['file']);
$type = mime_content_type($file);
$testfile = '-' . $file;
if (strpos($testfile, '/opt/') + strpos($testfile, '/mnt/') + strpos($testfile, '/tmp/') == 0) {
    die('F**k off hacker');
}
if ($type == 'application/octet-stream') {
    header('Content-disposition: attachment; filename="' . basename($file) . '"');
}
header("Cache-Control:");
header("Content-Type: {$type}");
streamFile($file, 0, 85);