Page 1 of 1

PHP Array to binary file

Posted: Thu Feb 20, 2014 10:47 am
by samestreet
Hello folks!

Well, I have an unusual question about binary files. I want to store a PHP array in a binary file, but, one of the array elements will be the content of a zip file. I'll explain:

$array = Array('some_info' => 'the_info', 'another_info' => 'the_another_info', 'file_content' => $loaded_zip_file);

I want to write a new binary file with the array information and, once I can open this binary file, I will read the 'file_content' element and create a temporary file. Basically, I want to create a new kind of file and (I think) it must have a binary header, right?

A better explain: I need a zip file and some information within a file, like a packed file or a datafile (Allegro users will understand).

Thanks in advance my friends!
Best regards

Re: PHP Array to binary file

Posted: Thu Feb 20, 2014 11:57 am
by Weirdan
Does it have to be binary? Do you have any compatibility constraints, like having a requirement to generate files compatible with some existing application?

Generally, php deals with binary data using pack()/unpack() functions.

Alternatively, you could just serialize() the array and store result in a file.