• Domů
  • Kontakt
  • O mně
  • Reference
  • Služby
Blue Orange Green Pink Purple

PHP: regulár na výpis použitých módů

?Ukaž kód PHP
<?php
 
 $tmp_source = preg_replace_callback("/\{mod_(.+)\}/", "process_mode", $tmp_source);
 
?>

Každý zpracovaný mód projde funkcí process_mode.

Číst více 0 Comments   |   Posted by admin
Led 17

PHP: omezení rychlosti stahování souboru s podporou download manageru

?Ukaž kód PHP
<?php
/*
   send_file( string $file [, int $rate ] )
 
   param $file - Path to the file to send
   param $rate - Speed limit of download in kB/s
*/
function send_file($file, $rate = 0) {
 
   // check if the file exists
   if (!is_file($file))
   {
      die('404 File Not Found');
   }
 
   // get the filename, extension, and size
   $filename = basename($file);
   $file_extension = strtolower(substr(strrchr($filename, '.'), 1));
   $size = filesize($file); 
 
   // set the mime type based on the extension
   switch($file_extension)
   {
      case 'exe':
         $ctype = 'application/octet-stream';
      break;
      case 'zip':
         $ctype = 'application/zip';
      break;
      case 'mp3':
         $ctype = 'audio/mpeg';
      break;
      case 'mpg':
         $ctype = 'video/mpeg';
      break;
      case 'avi':
         $ctype = 'video/x-msvideo';
      break;
      //  block access to sensitive file types
      case 'php':
      case 'inc':
         exit;
      break;
      default:
         $ctype='application/force-download';
   }
 
   // begin writing headers
   header('Cache-Control: private');
   header('Content-Type: ' . $ctype);
   header('Content-Disposition: attachment; filename=' . $filename);
   header('Content-Transfer-Encoding: binary');
   header('Accept-Ranges: bytes');
 
   // open the file for reading
   $fp = fopen($file, 'rb');
 
   // check if http_range was sent by client
   if(isset($_SERVER['HTTP_RANGE']))
   {
      // if so, calculate the range to use
      $seek_range = substr($_SERVER['HTTP_RANGE'], 6);
      $range = explode('-', $seek_range);
 
      if($range[0] > 0){
         $seek_start = intval($range[0]);
      }
      if($range[1] > 0){
         $seek_end  =  intval($range[1]);
      }
 
      // seek to the requested position in the file
      fseek($fp, $seek_start);
 
      // set the range response headers
      header('HTTP/1.1 206 Partial Content');
      header('Content-Length: ' . ($seek_end - $seek_start + 1));
      header(sprintf('Content-Range: bytes %d-%d/%d', $seek_start, $seek_end, $size));
   }
   else
   {
      // set default response headers
      header('Content-Length: ' . $size);
   }
 
   // set up the size of each piece of data we send
   $block_size = 1024;
   if($rate > 0)
   {
      // multiply by rate if specified
      $block_size *= $rate;
   }
 
   // prevent the script from timing out
   set_time_limit(0);
 
   // start sending the file
   while(!feof($fp))
   {
      // output data
      print(fread($fp, $block_size));
      flush();
 
      if($rate > 0)
      {
         // wait one second before next block if rate is specified
         sleep(1);
      }
   }
 
   // close the file
   fclose($fp);
}
?>
Číst více 7 Comments   |   Posted by admin
Led 17

PHP: omezení rychlosti stahování souboru

?Ukaž kód PHP
<?php
// local file that should be send to the client
$local_file = 'your-file.ext';
// filename that the user gets as default
$download_file = 'filename-in-browser.ext';
 
// 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!');
}
?>
Číst více 0 Comments   |   Posted by admin
Led 17

PHP: formátování bajtů

?Ukaž kód PHP
<?php
 
function format_bytes($bytes)
{
    $labels = array('B','KB','MB','GB','TB');
    for($x = 0; $bytes >= 1024 && $x < (count($labels) - 1); $bytes /= 1024, $x++);
    return(round($bytes, 2).' '.$labels[$x]);
}
 
?>
Číst více 0 Comments   |   Posted by admin
Led 17

PHP: odstranění query string klíče a hodnoty

?Ukaž kód PHP
<?php
 
function remove_querystring_var($url, $key) { 
	$url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&'); 
	$url = substr($url, 0, -1); 
	return $url; 
}
 
?>

Použití:

?Ukaž kód PHP
<?php
 
$qStr = "varOne=1&varTwo=2&key_to_remove=3&varFour=4"; //$_SERVER['QUERY_STRING']
$key="key_to_remove";
 
$qStr = remove_querystring_var($qStr,$key);
 
// vrací: varOne=1&varTwo=2&varFour=4
Číst více 0 Comments   |   Posted by admin
Previous Page 1 of 3

fandaa.name

    ¨
  • Hledání na webu


  • O mně
    Jmenuji se František ‚fandaa‘ Polášek. Je mi 18 let a mezi mé záliby patří programování (popř. skriptování a kódování) v jazycích (X)HTML, CSS, PHP, SQL, Javascript (+ AJAX), C/C++ a C#.
  • Rubriky
    • php (9)
  • Odkazy
    • Hry zdarma
    • Lukyn.com
    • Online-Firmy.com
    • Povinné ručení levně
    • SvětAut.com
    • Terorista.cz
  • Archives
    • Leden 2010




  • Home
  • Kontakt
  • O mně
  • Reference
  • Služby

© Copyright fandaa.name. All rights reserved.
Designed by FTL Free WordPress Themes brought to you by [i] Website Templates

Back to Top