Re: Display a database image from MSSQL database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 18, 2005 10:28 am, Alaor Barroso said:
> Hi... I need to display some images that exists inside one MSSQL
> server in a BLOB datatype field, but my code don't work...
>
> My code:

... contains NO error checking.  That's bad.

> <?
> $arg = $_GET["codPessoa"];
> mssql_connect("server", "web", "web");
> $sql = "SELECT Foto FROM Foto WHERE CodPessoa=$arg";
> $result = mssql_query($sql);
> $data = mssql_result($result, 0, "Foto");
> $data = stripslashes($data);

Nooooooooooooooooooo!

If you are calling stripslashes() on data coming out of your databsae, you
have almost for sure really screwed up much earlier in the process, by
having both Magic Quotes "on" and calling addslashes() (or
mysql_real_escape_string) or something similar.

You would only do stripslashes() here if you've hacked php.ini to use
Magic Quotes on data coming *OUT* of the database, which is really quite
rare to do -- You'd want that only on a site where, what?, you were
shlepping a bunch of stuff out of one database and into another???

> header("Content-type: image/gif");
> echo $data;
> exit;
> ?>
>
> And I access this page sending in the URL the text:
> .../showimage.php?codPessoa=xxx.
>
> I receive a strange code like
> Fh54757eFg554257eFrgtth547d54e7t8h54j87j85fd54ss7f...... Accessing
> this page by IE nothing happens but when a I try to access in Mozilla
> Firefox I got an error saying that the image cointain errors and
> cannot be displayed... If i try to show inside an img TAG in other
> page like <img src="patch/to/page" /> the code display a X error img,
> like if the image don't exist, but the code keep returning the strange
> code, so I believe that this is the image in a "string format" and
> something makes with the conversion for a real image format don't work
> very well.

Your stripslashes() corrupted the image, assuming it was valid in the
first place.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux