Read Byte Range From File

Read Byte Range From File script is used to returns first byte letter or line from file.

Demo :



From Byte Range     To Byte Range     
Return First bytes of file :   P  
Original File:
  
Test
       
  PHP:Hypertext free is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages    

Example :

In the above demo From Byte Range is default has been assigned by 0 and To Byte Range you will select your choose .for example if you select To Byte Range 3 and then click Find button the output will be displayed PHP.

Code :

Following code is use to Read Byte Range From File Script if you need code to copy and use to your website.


<?php
  function getBytes($file, $startByte, $endByte) {
  if ($endByte < $startByte) {
  die("Ending byte number must be greater than or equal to starting byte number!");
  }
  $fp = fopen($file, "rb") or die("Cannot open file");
  fseek ($fp, $startByte, SEEK_SET);
  while (!(ftell($fp) > $endByte)) {
  $data .= fgetc($fp);
  }
  fclose($fp) or die ("Cannot close file");
  return $data;
  }
  echo getBytes("File Path", 0, 10);
?>

In the above getBytes() function had three arguments those are first one is file path, second one is from byte range and last one is To Byte Range .The if the $endbyte less then $startByte the output will be displayed "Ending byte number must be greater than or equal to starting byte number!" . the fopen() function is used to file open function and fclose() function is used to file close function.

Free Download Script :

If you need to Read Byte Range From File click and download from following link.

Download




Content