Write byte array to file in PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hoanghwd
    New Member
    • May 2013
    • 1

    Write byte array to file in PHP

    Hi,
    I have array of bytes which is a pdf file
    Array ( [0] => 00100101 [1] => 01010000 [2] => 01000100 [3] => 01000110 [4] => 00101101 ....)
    I'm wondering how do I write my array into file in PHP
    Thanks
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    How about a for loop or a foreach loop?
    Code:
    $pdfData = "";
    foreach ($bytes as $byte) {
        $pdfData .= $byte;
    }
    And then you can use file_put_conten ts to write it to a file.

    P.S.
    If you're thinking you should write out each byte individually to the file, don't! A IO write operation is expensive, and it will take many many times longer to be writing the file out in a million byte-sized writes. Compile the output, and then write it.

    Comment

    Working...