Esempio n. 1
0
include $path . '/code/functions.php';
$directory = LOCALPATH . '/media/file';
//Это путь где хранятся файлы
if (!$_GET['file']) {
    die('Missing parameter!');
}
if ($_GET['file'][0] == '.') {
    die('Wrong file!');
}
@($fname = $_GET['file']);
$fname = preg_replace('/..\\//i', '', $fname);
$fullPath = $directory . '/' . $fname;
if (file_exists($fullPath)) {
    /* If the visitor is not a search engine, count the downoad: */
    if (!is_bot()) {
        inc_count($fname);
    }
    if ($fd = fopen($fullPath, "r")) {
        //следующая часть выводит файл
        $fsize = filesize($fullPath);
        $path_parts = pathinfo($fullPath);
        header("Content-type: application/octet-stream");
        header("Content-Disposition: filename=\"" . $path_parts["basename"] . "\"");
        header("Content-length: {$fsize}");
        header("Cache-control: private");
        //используется для прямого открытия файла
        while (!feof($fd)) {
            $buffer = fread($fd, 2048);
            echo $buffer;
        }
    }
Esempio n. 2
0
<?php

require_once 'scripts/counter_include.php';
inc_count();
Esempio n. 3
0
date_default_timezone_set("UTC");
$path = '../tmp/';
//sesion files folder
$file_name = 'sess_' . $_COOKIE['PHPSESSID'];
$file = $path . $file_name;
$atime = 300;
//5 min
function inc_count($path, $file, $atime)
{
    !is_dir($path) ? mkdir($path, 0755, true) : false;
    !file_exists($file) ? fopen($file, "w") : false;
    $time = file_get_contents($file);
    empty($time) ? file_put_contents($file, time() + $atime) : false;
    if ($time <= time()) {
        file_put_contents($file, time() + $atime);
    }
    if ($handle = opendir($path)) {
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != "..") {
                $time = file_get_contents($path . $entry);
                if ($time <= time()) {
                    unlink($path . $entry);
                }
            }
        }
        closedir($handle);
        return 'There is<b> ' . (count(scandir($path)) - 2) . ' </b>online users. (based on users active over the past ' . $atime / 60 . ' minutes)';
    }
}
echo inc_count($path, $file, $atime);