Jump to content

Binary File


monarlte

Recommended Posts

Hi.

 

I am wanting to write a php script that will output the binary value of a binary file.  When I print the current chunk, I just get the following printed to the screen: "Resource id #3".  And when I load the whole file contents into a string variable and then print that string, I just get jibberish printed to the screen.  Could somebody please tell me how I could print the binary value of the file?  Thank you.

 

$filename = 'song.mp3';

 

if (file_exists($filename)){

 

  //This will print jibberish

  $handle = fopen($filename, "r");

  $contents = fread($handle, $filesize);

  fclose($handle);

  print $contents;

 

  print '<br /><br />';

 

  //This next part will print "Resource id #3"

  $handle = fopen($filename, "r");

 

  while(!feof($handle)) {

    $chunk = fread($handle, 1024);

    print $handle;

    print '<br /><br />';

  }

 

}

Link to comment
https://forums.phpfreaks.com/topic/42794-binary-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.