response.BinaryWrite equivalent in php
Hi, I desperately need help from a php guru.
I am currently converting an asp.net site to php. The existing asp.net site retrieves images from a sqlserver database in the form of byte arrays. A byte array can then be instantly rendered to a page by using the following two lines (where bytArray is my byte array object):-
Response.ContentType = "Image/png"
Response.BinaryWrite(bytArray)
job done.
Simple huh! But can I find a way to do this using php? can I heck!
I have searched and searched for an answer but cannot find anything. I am learning php at the mo, have I missed something obvious? surely there must be a simple way to render a byte array to a php page?
Re: response.BinaryWrite equivalent in php
I've never dealt with ASP.NET or bytes/bits, so I absolutely cannot help you. I do know that PHP does not have a "byte" type of variable, which is what you'd be looking for, I'm pretty sure. I found this resource that may have some information to help you, but I couldn't find anything else.
Re: response.BinaryWrite equivalent in php
How is the data actually stored in the database? It may not actually be stored as a byte but rather converted to a byte array somewhere in code.
Re: response.BinaryWrite equivalent in php
Use fwrite or file_put_contents. If the file is being saved in Windows then you can use only fwrite and you need to ensure you open the file with the binary option 'wb'.
PHP Code:
$fhwnd = fopen($fileName, 'wb');
fwrite ($fhwnd, $string); // note this should be a string, not a byte array