I want to manipulate binary files.
this was just a test to concatinate 2 text files but it said
file_put_conten ts was undefined. the second parameter is suppoed to be
'mixed data', no idea what that is.
<?php
$t1 = file_get_conten ts('test1.txt') ;
$t2 = file_get_conten ts('test2.txt') ;
$result = file_put_conten ts('test3.txt', $t1 . $t2);
?>
But this was just a test anyway since file_get_conten ts 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 3 7012 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_conten ts was undefined. the second parameter is suppoed to be 'mixed data', no idea what that is.
The file_put_conten ts() 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_conten ts 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_conten ts on PHP 4.x would be to apply fopen
with ``wb'' as the switch and fputs for writing:
$fp = fopen("somenewf ile", "wb");
fputs($fp, $data_1 . $data_2);
fclose($fp);
Since file_get_conten ts() 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 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
Thanks, if I join your two answers together I get exactly what I want!
Herc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 record and get the
auto_insert ID from the response, and then loop through, appending data to
the record.
My table is simple. One unsigned int auto_increment field (DataID), and
one long blob field (BinaryData).
When I loop through the data to...
|
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 delta binary is pretty huge in size. I
have 1 byte file and 2 bytes file, the delta should be 1
byte but somehow it turns out to be 249 bytes using binary
formatter. I guess serialization has some other things
added to the delta file.
|
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, IF(activated=1,'',' (NOT YET ACTIVATED)')) AS uname FROM tbuser
I get:
MySQL Error Occured
|
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
|
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 binary
mode.
according to me, notepad opens files and each byte of the file
read, it converts that byte from ascii to its correct character and
displays
| |
by: vim |
last post by:
hello everybody
Plz tell the differance between binary file and ascii
file...............
Thanks
in advance
vim
|
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:
|
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 original form. The problem is tha the binary
source that I extract from the text file seems to be diferent from the
source I saved. Here is my code:
1)
handle=file('image.gif','rb')
|
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 successfully created and used txt files.
I am trying to save then load in an array of pointers to objects:
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |