Dear All
Im having some dificulty here:
I found a great PHP code by Catalin Mihaila that reads a SRC (Sinclair
Spectrum $SCREEN Image Format) and tranforms it into PNG format to show
onscreen by the PHP gd2 Library.
The problem is that im trying to translate the 'fread' structure into a
MySQL blob reading, as follows:
Original file access code:
$zxscr = fread($handle, 6144); // first 6144 bytes of file
$attrs = fread($handle, 768); // last 768 bytes of file
My actual MySQL access code:
$zxscr = substr($row[Image], 0, 6144); // first 6144 bytes
of MySQL field "Imagem" inside table "Perguntas"
$attrs = substr($row[Image], -768); // last 768 bytes of
MySQL field "Imagem" inside table "Perguntas"
Here's the original full CODE (for reading the file from servers directory):
$filename=$_GET['scrimg'];
if(!$filename) error("Invalid filename");
$handle = fopen($filename, "r");
if(filesize($filename)<>6912) { fclose($handle); error("Size
of file must be 6912 bytes"); }
$zxscr = fread($handle, 6144); // first 6144 bytes of file
$attrs = fread($handle, 768); // last 768 bytes of file
fclose($handle);
And here's what i changed it into (for reading from a blob field inside
MySQL db):
mysql_connect("localhost", "user", "password") or die("Could
not connect: " . mysql_error());
mysql_select_db("jb-ntg");
$result = mysql_query("SELECT Numero, Nome, Imagem FROM
Perguntas WHERE Numero = jogo");
$zxscr = substr($row[Image], 0, 6144); // first 6144 bytes
of MySQL field "Imagem" inside table "Perguntas"
$attrs = substr($row[Image], -768); // last 768 bytes of
MySQL field "Imagem" inside table "Perguntas"
Here's the structure of the DB "jb-ntg"
CREATE TABLE `perguntas` (
`Numero` int(11) NOT NULL auto_increment,
`Nome` mediumtext NOT NULL,
`Imagem` blob NOT NULL,
`Acessos` int(11) NOT NULL default '0',
`Certas` int(11) NOT NULL default '0',
PRIMARY KEY (`Numero`)
) TYPE=MyISAM AUTO_INCREMENT=3 ;
But i get a blank image (with the right dimensions, so the script must be
ok) the only problem i think is the fact that in the original code i could
get the first 6144 bytes and last 768 bytes of the file, but using the MySQL
blob i apparently cant at least using the substr, and i sincerely have no
idea of the binary equivalent of the fread for blob files.
Anyone can help?
I never coded in PHP and this is my first try at this new language, as you
should remember im trying to make a "Name the Game" PHP game devoted to ZX
Spectrum, and i will, i just need a few guiding lines over here and there.
Thanks for any support in advance,
RootShell