473,320 Members | 2,071 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,320 software developers and data experts.

Reading Binary Files in PHP

5
Recently I need to write a PHP script that would process a binary file I had created in my VB program. Can PHP do this? and how?
PS: Sorry for my bad English.
Jun 6 '07 #1
15 5840
jx2
228 100+
dont worry about your english :-) its better then mine :-)

u miht want to see this http://us3.php.net/manual/en/function.fopen.php
simple use fopen("urefile",'rb'); - 'b' for binary
Jun 6 '07 #2
ihere
5
dont worry about your english :-) its better then mine :-)

u miht want to see this http://us3.php.net/manual/en/function.fopen.php
simple use fopen("urefile",'rb'); - 'b' for binary
It is not so simple as you think. I have a binary file test.qbt that I had created in my VB6 program. In this binary file: simple text, picture and expression. Now i have to read all data from that file and write to browser (text, picture and expression). I dont know how? Please help me!!!!
Jun 6 '07 #3
jx2
228 100+
[PHP]
<?php
session_start();
$fp=fopen("p1.php",'rb');
$i=0;
do{
fseek($fp,$i);
$buff=fread($fp,1);

echo ord($buff))."<br>\n";
$i++;
}while($i<=filesize('p1.php'));
[/PHP]

that is the way to do it-(i hope :-)
it reads file byte by byte and displays as binary

by the way how u going to use those images?
i hope it helps
jx2
Jun 6 '07 #4
jx2
228 100+
of course p1.php its only as an example :-)
let me know if that is what you wanted...
Jun 6 '07 #5
ihere
5
of course p1.php its only as an example :-)
let me know if that is what you wanted...
No i have a test file: click here: http://www.nguyentiendat.narod.ru/test.qbt that i had created in VB6. Now i have to read it from PHP and show all data in browser (include text, picture,...). I dont know how....
Jun 6 '07 #6
jx2
228 100+
No i have a test file: click here: http://www.nguyentiendat.narod.ru/test.qbt that i had created in VB6. Now i have to read it from PHP and show all data in browser (include text, picture,...). I dont know how....
but how the structure of file looks like? how did you created it? i gues its a kind of the databases...
Jun 6 '07 #7
jx2
228 100+
but how the structure of file looks like? how did you created it? i gues its a kind of the databases...
i'll be back in the evening :-) i c what is it :-) cool :-)
Jun 6 '07 #8
pbmods
5,821 Expert 4TB
Changed thread title: Removed superfluous '????' and 'help'.
Jun 6 '07 #9
ihere
5
but how the structure of file looks like? how did you created it? i gues its a kind of the databases...
Look at: http://www.nguyentiendat.narod.ru/testfile.pdf Right click and choose Save Target As
I'm looking for your answer
Jun 7 '07 #10
pbmods
5,821 Expert 4TB
Please do not bump your posts. Thanks!
Jun 8 '07 #11
Motoma
3,237 Expert 2GB
You will need to know the file format structure of the binary file you are using. Do you?
Jun 8 '07 #12
ihere
5
You will need to know the file format structure of the binary file you are using. Do you?
Of cause i know, but i dont know how to transfer data from file to normal data for showing on browse, example picture,...
Jun 9 '07 #13
bucabay
18
Of cause i know, but i dont know how to transfer data from file to normal data for showing on browse, example picture,...
You have to send the right HTTP Headers that define the Content-Type.. eg:
[PHP]
header('Content-Type: image/png');[/PHP]

If you image is a png image.

Then read the binary image data from teh file and output it in the HTTP Body.

[PHP]
// send HTTP headers
header('Content-Type: image/png');
header('Content-Length: '.filesize($binary_file_path));

// send HTTP Body
$fp = fopen($binary_file_path, 'rb'); // open file pointer
fpassthru($fp); // dump file stream to http
fclose($fp);

[/PHP]
Jun 9 '07 #14
You have to send the right HTTP Headers that define the Content-Type.. eg:
[PHP]
header('Content-Type: image/png');[/PHP]

If you image is a png image.

Then read the binary image data from teh file and output it in the HTTP Body.

[PHP]
// send HTTP headers
header('Content-Type: image/png');
header('Content-Length: '.filesize($binary_file_path));

// send HTTP Body
$fp = fopen($binary_file_path, 'rb'); // open file pointer
fpassthru($fp); // dump file stream to http
fclose($fp);

[/PHP]
I think this is a stupid question..but how do you dump it in the http body? I cant seem to make it appear in my webpage. All I get is a corrupted file. Thanks for your reply!
Jun 12 '07 #15
Motoma
3,237 Expert 2GB
I think this is a stupid question..but how do you dump it in the http body? I cant seem to make it appear in my webpage. All I get is a corrupted file. Thanks for your reply!
This example was assuming that the entire file was one png. If that is not the case, you will need to break your data into it's constituent pieces.
Jun 12 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: christos panagiotou | last post by:
hi all I am trying to open some .raw files that represent images (256x256, 8 bit per pixel, no header) in a c++ program I cannot copy paste the module here as it uses a method from the VTK...
3
by: Olivier Maurice | last post by:
Hi all, I suppose some of you know the program Redmon (type redmon in google, first result). This neat little tool allows to hook up any functionality to a printer by putting the file printed...
7
by: laclac01 | last post by:
So I am converting some matlab code to C++. I am stuck at one part of the code. The matlab code uses fread() to read in to a vector a file. It's a binary file. The vector is made up of floats,...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
5
by: rnorthedge | last post by:
I am working on a code library which needs to read in the data from large binary files. The files hold int, double and string data. This is the code for reading in the strings: protected...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
2
by: amfr | last post by:
On windows, is there anything special I have to do to read a binary file correctly?
30
by: siliconwafer | last post by:
Hi All, I want to know tht how can one Stop reading a file in C (e.g a Hex file)with no 'EOF'?
2
by: nnimod | last post by:
Hi. I'm having trouble reading some unicode files. Basically, I have to parse certain files. Some of those files are being input in Japanese, Chinese etc. The easiest way, I figured, to distinguish...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.