views:

126

answers:

1

Hi ! I have pictures in a database and i want to read it out and display it as a picture. However i get strange long charakters as result.

my code:

<?php
/**
* @version 1.0 $
* @package HelloWorld
* @copyright (C) 2010 BlaBlbb
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
 // assemble query
$query = '
    SELECT *
    FROM artikel
';

$database->setQuery($query);
if ( !$database->query() ) {
echo "<script type='text/javascript'>
         alert('".$database->getErrorMsg()."');
      </script>";
} else {
$rows = $database->loadObjectList();
}
echo '<table>';
foreach ($rows as $rowi)
{

echo '<tr><td>'.$rowi->Artikelname.'</td>';
echo '<td>'.$rowi->Stueckpreis.'</td>';
echo '<td>'.$rowi->Gewicht.'</td>';
echo '<td>'.$rowi->Lagerstand.'</td>';
echo '<td>'.$rowi->Aenderungsdatum.'</td>';
echo '<td><img>'
.$rowi->Foto.
echo'</img></td></tr>';


}
echo '</table>';
?>
<!--<h1>Hallo Welt</h1>
<p>Das ist ein Test</p>
<p>juhuu</p>
-->

any suggestions? i wanna have the image in the same file if possible... i am very new to joomla so i dont know how to use it with a second php that creates the picture...

A: 

You're seeing strange characters because you're just echoing the raw image data into the page. In order to serve an image, the browser must request it as a file from the server*.

This means that you need to either need to:

  1. write your image data to disk, then give the browser the URL to the file in the <img> tag, or
  2. you need to create a script that returns the proper Content-type header for the image type and echos the image data then give the browser the URL to the script in the <img> tag.

*: (Yes, there's data:, but that's not a suitable solution for most cases. Especially this one.)

Charles