php reading and writing to binary files

March 11th, 2010 | Posted by jane under enart.qthx.com with
  • I want to read and write the xmp metadata packet inside an adobe pdf file. I can successfully read out the packets with a grep pattern, but writing it back is much more complex. I have an idea of how it is done, but I'm wondering if anybody has done this. How can I use php to write a new xmp metadata packet into an adobe pdf file without corrupting the file?


  • This is specifically about writing an xmp metadata packet inside an adobe pdf file. It seems to involve udating the "dictionary" (?) or something and whatever other requirements to prevent the file from becoming corrupted.


  • /* binary file read & write */ // for binary file read and write we have to use the mode 'b' b for binary //in php to open a binary file use $filename="xyz.pdf"; $fp=fopen($filename,"rb"); $contents=fread($fp,filesize($filename)); fclose($fp); /* in the contents u can modify what xmp u want */ again $filename="xyz.pdf"; $fp=fopen($filename,"wb"); if (fwrite($fp, $contents) === FALSE) { echo "Cannot write to file ($filename)"; exit; } fclose($fp); try with this method regards indianguysiva-ga


  • Purpose: Binary-safe file read Usage: string fread (int fp, int length) Availability: PHP 3, PHP 4 >= 4.0.0 fread() reads up to length bytes from the file pointer referenced by fp. Reading stops when length bytes have been read or EOF is reached, whichever comes first. // get contents of a file into a string $filename = "/usr/local/something.txt"; $fd = fopen ($filename, "r"); $contents = fread ($fd, filesize ($filename)); fclose ($fd);


  • int fwrite (int fp, string string [, int length]) fwrite() writes the contents of string to the file stream pointed to by fp. If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first.







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about php reading and writing to binary files , Please add it free.
    edit