PDA

Click to See Complete Forum and Search --> : response.BinaryWrite equivalent in php


vadercole
Feb 13th, 2009, 04:07 AM
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?

kows
Feb 13th, 2009, 06:13 AM
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 (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_23325692.html) resource that may have some information to help you, but I couldn't find anything else.

ngreenwood6
Feb 13th, 2009, 08:01 AM
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.

visualAd
Feb 13th, 2009, 08:23 AM
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'.

$fhwnd = fopen($fileName, 'wb');

fwrite ($fhwnd, $string); // note this should be a string, not a byte array