Categories

Get bluray release dates

<?php
 
if(isset($_GET['movie'])) {
    $pdata = $_GET['movie'];
} else {
    die("");
}
 
if (strlen($pdata) < 5) { die("At least 5 letters in search."); }
 
$data = file_get_contents("http://bluray.highdefdigest.com/releasedates.html");
preg_match_all(‘/<li><b>.*<a href=\"http\:\/\/bluray\.highdefdigest\.com\/[0-9]+\/.*\.html\">.*<\/a>/’, $data, $results);
 
foreach ($results[0] as $linkki) {
        preg_match(‘/http\:\/\/bluray.highdefdigest\.com\/[0-9]+\/.*\.html/’, $linkki, $linkit[]);
        preg_match(‘/html\">.*<\/a>/’, $linkki, $leffax);
        $leffa = str_replace(‘html">’, ”, $leffax[0]);
        $leffa = str_replace(‘</a>’, ”, $leffa);
        $leffatx[] = trim($leffa);
}
 
$paskaa = "-1";
 
$f = "0";
 
$checkki = "0";
foreach ($leffatx as $movie) {
$insidecheck = "0";
        $paskaa++;
 
    if (preg_match("/^$pdata/i", $movie)) {
        $neekeri[] = $movie;
        $checkki++;
    }
 
    if ($checkki == "4") {
        if ($_GET['all'] != "yes") {
            die("To see more results, goto: script.php?all=yes&movie=$pdata\n");
        }
    }
 
        if (preg_match("/^$pdata/i", $movie)) {
                $datelinkki = $linkit[$paskaa][0];
                $datedata = file_get_contents("$datelinkki");
                preg_match_all(‘/Street Date.*/’, $datedata, $dateresults);
                if(isset($dateresults[0][0])) {
                        echo "$movie – ".$dateresults[0][0]."\n";
            $f = "1";
            $insidecheck = "1";
                }
        }
    if ($insidecheck != "1") {
        if (preg_match("/$pdata/i", $movie)) {
                $datelinkki = $linkit[$paskaa][0];
                $datedata = file_get_contents("$datelinkki");
                preg_match_all(‘/Street Date.*/’, $datedata, $dateresults);
                if(isset($dateresults[0][0])) {
                        echo "$movie – ".$dateresults[0][0]."\n";
            $f = "1";
                }
        }
    }
 
}
 
if($f == "0") {
    echo " ".$pdata." returned 0 hits.";
}
 
?>

Force a file to download

 

function downloadFile($file){
        $file_name = $file;
        $mime = ‘application/force-download’;
    header(‘Pragma: public’);     // required
    header(‘Expires: 0′);        // no cache
    header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0′);
    header(‘Cache-Control: private’,false);
    header(‘Content-Type: ‘.$mime);
    header(‘Content-Disposition: attachment; filename="’.basename($file_name).’"’);
    header(‘Content-Transfer-Encoding: binary’);
    header(‘Connection: close’);
    readfile($file_name);        // push it out
    exit();
}

from http://www.tecnocrazia.com/

Limit file download speed

//Author: Jonas John
// local file that should be send to the client
$local_file = ‘test-file.zip’;
  
// filename that the user gets as default
$download_file = ‘your-download-name.zip’;
  
// set the download rate limit (=> 20,5 kb/s)
$download_rate = 20.5;
  
if(file_exists($local_file) && is_file($local_file)) {
  
    // send headers
    header(‘Cache-control: private’);
    header(‘Content-Type: application/octet-stream’);
    header(‘Content-Length: ‘.filesize($local_file));
    header(‘Content-Disposition: filename=’.$download_file);
  
    // flush content
    flush();
  
    // open file stream
    $file = fopen($local_file, "r");
  
    while (!feof($file)) {
  
        // send the current file part to the browser
        print fread($file, round($download_rate * 1024));
  
        // flush the content to the browser
        flush();
  
        // sleep one second
        sleep(1);
    }
  
    // close file stream
    fclose($file);
  
}
else {
    die(‘Error: The file ‘.$local_file.’ does not exist!’);
}

List images in a folder

// the directory, where your images are stored
$imgdir = ‘/images/’;
 
// list of filetypes you
$allowed_types = array(‘png’,'jpg’,'jpeg’,'gif’); want to show
 
$dimg = opendir($imgdir);
while($imgfile = readdir($dimg))
{
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
{
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}
// total image number
$totimg = count($a_img);
 
for($x=0; $x < $totimg; $x++)
{
$size = getimagesize($imgdir.’/’.$a_img[$x]);
 
// do whatever
$halfwidth = ceil($size[0]/2);
$halfheight = ceil($size[1]/2);
echo ‘
<li><img src="%27.$imgdir.%27%27.$a_img%5B$x%5D.%27"></li>
 
‘;
}

Compress css files

header(‘Content-type: text/css’);
ob_start("compress");
function compress($buffer) {
  /* remove comments */
  $buffer = preg_replace(‘!/\*[^*]*\*+([^/][^*]*\*+)*/!’, ”, $buffer);
  /* remove tabs, spaces, newlines, etc. */
  $buffer = str_replace(array("\r\n", "\r", "\n", "\t", ‘  ‘, ‘    ‘, ‘    ‘), ”, $buffer);
  return $buffer;
}

/* your css files */
include(‘master.css’);
include(‘typography.css’);
include(‘grid.css’);
include(‘print.css’);
include(‘handheld.css’);

ob_end_flush();