Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Get binary data from file

Here is a quick example how to get binary data from any file:

<?php
//call function when contents loaded
ob_start("get_bytes");
function to_binary($x, $numbits = 8) { 
    // Convert to binary 
    $bin = decbin($x); 
    $bin = substr(str_repeat(0,$numbits),0,$numbits - strlen($bin)) . $bin; 
    // Split into x 4-bits long 
    $rtnval = ''; 
    for ($x = 0; $x < $numbits/4; $x++) { 
        $rtnval .= '' . substr($bin,$x*4,4); 
    } 
    // Get rid of first space. 
    return ltrim($rtnval); 
 }
//get bytes of string
function get_bytes($buffer)
{
	$str = "";
	$l = strlen($buffer);
	for($i = 0; $i < $l; $i++)
	{
		$str .= to_binary(ord($buffer[$i]));
		//$str .= $buffer[$i]." ";
	}
	return $str;
}
//read file
readfile("./somepic.png");
ob_end_flush();
?>

 


You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus