Forum Moderators: coopster

Message Too Old, No Replies

Reading file in as binary data

         

sharyn

12:51 am on Nov 12, 2004 (gmt 0)

10+ Year Member



I'm trying to use the Zend ZIP class [zend.com] and at some point I have to read my file into a binary data string and then store it into the Zip file. This may be a very simple process, but I don't know how to do it. The documentation at Zend just says


//add the binary data stored in the string 'filedata'
$filedata = "(read your file into $filedata)";
$zipfile -> add_file($filedata, "dir/file.txt");

The files are of varying types : text, jpg, tif, xls, etc...

I've looked around various sites including this one, but I may be typing in the wrong search words. In anycase, can anyone give me a clue?

Thanks a mill,
- sharyn

dmorison

9:15 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

If you're using PHP > 4.3.0 you can use file_get_contents() [uk.php.net].

Prior to 4.3.0; you would use fopen() and fread(). The manual pages for these functions contain examples for reading an entire file into a string.

Hope this helps!

sharyn

11:48 pm on Nov 15, 2004 (gmt 0)

10+ Year Member



DMorrison,

Thanks so much! file_get_contents() was exactly what I needed! :D Thanks a mill!

- sharyn