read a file n convert it to its hexadecimal equivalent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nabanita
    New Member
    • Mar 2010
    • 9

    #1

    read a file n convert it to its hexadecimal equivalent

    is there any way in which i could open a file in php to read a file n convert it to its hexadecimal equivalent..
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    See example #2:


    It's wondrous what a few minutes googling will find you.

    Comment

    • philipwayne
      New Member
      • Mar 2010
      • 50

      #3
      The above is not complete it reads the actual files contents but does not convert it to hexadecimal.

      Code:
      $filename = "c:\\files\\somepic.gif";
      $handle = fopen($filename, "rb");
      $contents = [u]bin2hex[/u]( fread( $handle, filesize($filename) ) );
      fclose($handle);
      EDIT:
      Oh and use
      Code:
      pack( "H*", $contents );
      to convert it back.
      Last edited by philipwayne; Mar 15 '10, 05:28 PM. Reason: Adding information

      Comment

      Working...