473,387 Members | 1,863 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,387 software developers and data experts.

Write byte array to file in PHP

Hi,
I have array of bytes which is a pdf file
Array ( [0] => 00100101 [1] => 01010000 [2] => 01000100 [3] => 01000110 [4] => 00101101 ....)
I'm wondering how do I write my array into file in PHP
Thanks
May 10 '13 #1
1 9151
Atli
5,058 Expert 4TB
How about a for loop or a foreach loop?
Expand|Select|Wrap|Line Numbers
  1. $pdfData = "";
  2. foreach ($bytes as $byte) {
  3.     $pdfData .= $byte;
  4. }
  5.  
And then you can use file_put_contents to write it to a file.

P.S.
If you're thinking you should write out each byte individually to the file, don't! A IO write operation is expensive, and it will take many many times longer to be writing the file out in a million byte-sized writes. Compile the output, and then write it.
May 11 '13 #2

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

Similar topics

3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
1
by: Andre Ranieri | last post by:
I'm having trouble programatically inserting an Excel file into an Image column in our CRM package's SQL 2000 database. The function appears to work ok, but when I attempt to access the file through...
1
by: Mark | last post by:
Hello. How can I write binary data from byte to some file on disk? Thank you.
2
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
3
by: DaveS | last post by:
Hi! I am returning a byte array from a function and wish to print out the values of the array. However, I get Microsoft VBScript runtime error '800a000d' Type mismatch Here is the gist of...
2
by: Chris | last post by:
How do I save an array of bytes to a file? I am binding a update parameter to a fileupload control. It passes the file to my object as a Filebytes datatype. I am assuming it is just an array of...
0
by: lovecarole | last post by:
hi, i am the student who should write a program about reading wav file and do the DFT. actually i don't know how to read data of the wav song and save it into the array... if i want to read...
3
by: eran otzar | last post by:
ok i want to take a byte array byte buffer = ASCIIEncoding.ASCII.GetBytes("hello there"); now yes we turned it into a byte, but now i want to write the represent to contents of the byte...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.