Google Answers Logo
View Question
 
Q: php reading and writing to binary files ( No Answer,   3 Comments )
Question  
Subject: php reading and writing to binary files
Category: Computers > Programming
Asked by: phoogoo-ga
List Price: $25.00
Posted: 18 Sep 2004 20:16 PDT
Expires: 18 Oct 2004 20:16 PDT
Question ID: 403105
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?

Clarification of Question by phoogoo-ga on 25 Sep 2004 18:24 PDT
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.
Answer  
There is no answer at this time.

Comments  
Subject: Re: php reading and writing to binary files
From: fornn-ga on 22 Sep 2004 10:02 PDT
 
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.
Subject: Re: php reading and writing to binary files
From: fornn-ga on 22 Sep 2004 10:03 PDT
 
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);
Subject: Re: php reading and writing to binary files
From: indianguysiva-ga on 27 Sep 2004 04:53 PDT
 
/* 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

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy