473,230 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

concat 2 binary files?

I want to manipulate binary files.

this was just a test to concatinate 2 text files but it said
file_put_contents was undefined. the second parameter is suppoed to be
'mixed data', no idea what that is.

<?php
$t1 = file_get_contents('test1.txt');
$t2 = file_get_contents('test2.txt');
$result = file_put_contents('test3.txt', $t1 . $t2);
?>

But this was just a test anyway since file_get_contents uses strings,
can someone just give me the code to concat 2 binary files? I'll be
manipulating the files before I concatinate them, so putting the data
into 2 arrays of bytes 1st would be best.

Herc

Jul 17 '05 #1
3 6742
he*****@hotmail.com wrote:
I want to manipulate binary files.

this was just a test to concatinate 2 text files but it said
file_put_contents was undefined. the second parameter is suppoed to be
'mixed data', no idea what that is.

The file_put_contents() function is only supported on PHP v >= 5; the
indication mixed data means that it can be anything from a scalar to an
array.
But this was just a test anyway since file_get_contents uses strings,
can someone just give me the code to concat 2 binary files? I'll be
manipulating the files before I concatinate them, so putting the data
into 2 arrays of bytes 1st would be best.


An alternative for file_put_contents on PHP 4.x would be to apply fopen
with ``wb'' as the switch and fputs for writing:

$fp = fopen("somenewfile", "wb");
fputs($fp, $data_1 . $data_2);
fclose($fp);

Since file_get_contents() is binary safe, the binary data will be
untouched and the merge successful, provided that the binary data
actually can be merged this way...
JW
Jul 17 '05 #2
I want to manipulate binary files.


Add error handling as appropriate...
$strFile1 = "blue.bin";
$strFile2 = "green.bin";
$strFile3 = "bluegreen.bin";
// open for read/binary-safe
$objFH = fopen( $strFile1, "rb" );
$strBuffer1 = fread( $objFH, filesize( $strFile1 ) );
fclose( $objFH );
// open for read/binary-safe
$objFH = fopen( $strFile2, "rb" );
$strBuffer2 = fread( $objFH, filesize( $strFile2 ) );
fclose( $objFH );
// ...manipulate buffers here...
$strBuffer3 = $strBuffer1 . $strBuffer2;
// open for write/binary-safe
$objFH = fopen( $strFile3, "wb" );
fwrite( $objFH, $strBuffer3 );
fclose( $objFH );
---
Steve

Jul 17 '05 #3
Thanks, if I join your two answers together I get exactly what I want!

Herc

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Garrett Kajmowicz | last post by:
I'm needed to insert large BLOBs into a database. With the 1MB packet limit, sending larger amounts of data would be difficult, so I had a neat idea. I would do an initial insert of an empty...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
3
by: nickdevx | last post by:
Damn it this "illegal mix of collashit" messages are driving me nuts!! What's wrong with the following statement? SELECT userid, CONCAT(username,' / ',firstname,' ',lastname,' / ', email,...
8
by: dagecko | last post by:
Hi I would like to know how to detect if a file is binary or not. It's important for me but I don't know where to start. Ty
10
by: joelagnel | last post by:
hi friends, i've been having this confusion for about a year, i want to know the exact difference between text and binary files. using the fwrite function in c, i wrote 2 bytes of integers in...
68
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
4
by: Martin Evans | last post by:
Hi, I'm getting: DBD::DB2::db do failed: SQL0440N No authorized routine named "CONCAT" of type "FUNCTION" having compatible arguments was found. SQLSTATE=42884 for some SQL like this:
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
15
by: JoeC | last post by:
I am writing a program that I am trying to learn and save binary files. This is the page I found as a source: http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html I have...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.