Page 1 of 2
only get a red cross
Posted: Mon Jun 09, 2003 12:27 am
by devmatch
hi,
i'm trying to get a picture from the database. it's in a blobfile. seems ok. but when i read it from the db theres a red cross???
any ideas?
THX
Posted: Mon Jun 09, 2003 1:32 am
by delorian
Could you tell us more

Maybe, you should include your script in your post.
scripts...
Posted: Mon Jun 09, 2003 1:43 am
by devmatch
request if x is set
...
echo ( "<img src=\"viewImg.php?product_id=" .
$product[id] . "\" width=\"" . $product[width] . "\" height=\"" . $product[height] ."\" alt=\"" . $product[name] . "\" align=\"left\">\n" );
...
viewImg.php
Code: Select all
<?
require ("./common/config.inc.php");
print "test";
// test for product_id
if(!isset($product_id))
{
echo ( "<!-- No Product ID Found. -->\n " );
exit;
}
if ( ( $dbh = mysql_connect( $dbServer, $dbUser, $dbPassword )) > 0 )
{
$res = mysql_db_query($dbDatabase, "SELECT product_image FROM $productTable WHERE product_id = '$product_id'", $dbh );
if(mysql_num_rows($res) == 0)
{
echo ( "<!-- No Image Found For Product ID $product_id. -->\n " );
exit;
}
else
{
$row = mysql_fetch_array($res);
Header( "Pragma: no-cache" );
Header( "Content-type: image/$row[product_image_format]");
echo ( $row["product_image"] );
}
$dbh = mysql_close();
}
?>
mod_edit: added Code: Select all
tags[/size]
there is a problem when i call viewImg.php the script will not be called!!!
so there is no picture (area with red cross) in the request script:(
any idea? i think i couldn't download a file??? why! are there another parameters then "file_uploads = On". there is no picture in dir by using example scripts for uploading:(
well seems fileupload runs quit normal. but the above scripts example not??? the file is saved in a blob(look example), but read seems not working. above its the normal way to read a blob from a $result!
any ideas???
THX
Posted: Mon Jun 09, 2003 3:20 am
by volka
at least
print "test";
destroys your script. You cannot send headers after you printed something and the string makes the images data invalid.
Did you test the remaining script? Try
Code: Select all
<?php
require ("./common/config.inc.php");
// test for product_id
if(!isset($product_id))
{
echo ( "<!-- No Product ID Found. -->\nNo Product ID Found." );
exit;
}
else if ( ( $dbh = mysql_connect( $dbServer, $dbUser, $dbPassword )) !== FALSE)
{
$res = mysql_db_query($dbDatabase, "SELECT product_image FROM $productTable WHERE product_id = '$product_id'", $dbh );
if(mysql_num_rows($res) == 0)
{
echo ( "<!-- No Image Found For Product ID $product_id. -->\nNo Image Found For Product ID $product_id." );
exit;
}
else
{
$row = mysql_fetch_array($res);
// Header( "Pragma: no-cache" );
// Header( "Content-type: image/$row[product_image_format]");
echo ( strlen($row["product_image"]) );
}
mysql_close($dbh);
}
else
{
echo mysql_error();
}
?>
and do not call it via <img src="..."> but as html-page to check the (debug-)output.
still not working
Posted: Mon Jun 09, 2003 3:45 am
by devmatch
still not working:( is there a problem with <img src...???
i've tried to save the img in a directory, but there might be no permission to add a file via the client browser...
THX for LISTENING;)
Posted: Mon Jun 09, 2003 4:45 am
by volka
and do not call it via <img src="..."> but as html-page to check the (debug-)output.
Just call the script as the img-tag would do, but call it yourself from the nav-bar of your browser.
This way you can see the error output of the script (if there is any).
Note: my changes on your script will not display the image data anymore but the data length
// Header( "Pragma: no-cache" );
// Header( "Content-type: image/$row[product_image_format]");
echo ( strlen($row["product_image"]) );
it's only for debuging
Posted: Mon Jun 09, 2003 5:11 am
by Wayne
Are you escaping slashes, if you are retrieving the file contents from the database and they contain slashes, this would corrupt the image and it will not display. you may or may not need this depending on how your server is configured.
try
Code: Select all
echo stripslashes($rowї"product_image"]);
testing,testing,testing...
Posted: Mon Jun 09, 2003 5:49 am
by devmatch
... nothing...
next test results in...
<?
mysql_connect("localhost","root","");
mysql_select_db("couponing");
$zeiger=mysql_query("select product_image from products where product_id = 100");
$res=mysql_fetch_array($zeiger);
Header( "Pragma: no-cache" );
Header( "Content-type: image/jpg");
echo ( $res["product_image"] );
?>
an example results in a pop up for download the script???
sorry for this confusion... but i test everything for working...damn:(
THX for your pleasure:)
yeah i found the error!!!
was in the insert of the data:(
sorry ... big program no eyes!
if ( $valid_image ) $productInfo["product_image"] = addslashes(fread(fopen($product_image, "r

"), filesize($product_image)));
[/b]
Posted: Mon Jun 09, 2003 6:00 am
by qartis
What's the code that puts the image's data into the database?
sorry for ymy problems:(
Posted: Mon Jun 09, 2003 6:39 am
by devmatch
alternative i tried to upload the file in the webservers dir:
failed to create stream: Permission denied in c:\web\root\couponingenv\admin\addcoupon.php on line 28

Posted: Mon Jun 09, 2003 10:11 am
by qartis
Code: Select all
if ( $valid_image )
$productInfoї"product_image"] = addslashes(fread(fopen($product_image, "r"), filesize($product_image)));
}
Is the code you're using to prepare the binary data to be popped into the database, so all of the quotes are escaped with slashes. To call it back just as before, you'll need to replace
Code: Select all
echo ($rowї"product_image"]);
With
Code: Select all
echo stripslashes($rowї"product_image"]);
Posted: Mon Jun 09, 2003 10:12 am
by qartis
And I just realized, you might also need to fopen() the $product_image as "rb", not just "r".
using windoof
Posted: Tue Jun 10, 2003 1:07 am
by devmatch
it is possible to change the user rights from r to rw???
Re: using windoof
Posted: Tue Jun 10, 2003 2:29 am
by devmatch
devmatch wrote:it is possible to change the user rights from r to rw in windows???
find my solution script:)
Posted: Tue Jun 10, 2003 6:20 pm
by devmatch
Code: Select all
<?php
if ($img1_name == "") {
?>
<html>
<head>
<title>Upload a File</title>
</head>
<!--
Formular: in einem Filepanel kann der Name
des lokalen Files angegeben werden,
das auf den Server hochgeladen werden soll.
-->
<body>
<h1>Upload a File</h1>
<form enctype="multipart/form-data" method="post"
action="<?php echo $PHP_SELF?>">
<p><strong>File to Upload:</strong><br>
<input type="file" name="img1" size="30"></p>
<P><input type="submit" name="submit"
value="Upload File"></p>
</form>
<?php
}
else {
$curdir=getcwd();
exec("/usr/local/info-sys/cgi-bin/phptouch
$SCRIPT_FILENAME $curdir/tmp/$img1_name",$t,$status);
if ($status > 2) { die ("<br>$t[0]"); }
if ($status == 2) {
print("File already exists, will be overwritten");
}
move_uploaded_file("$img1", "./tmp/$img1_name");
exec("phpchown $SCRIPT_FILENAME
$curdir/tmp/$img1_name",$r,$status);
if ($status >1) {
print("<br>$r[0]");
}
?>
<html>
<head>
<title>File Upload!</title>
<body>
<P>You sent: <?php echo "$img1_name"; ?>, a
<?php echo "$img1_size"; ?>
byte file with a mime type of
<?php echo "$img1_type"; ?>.</p>
<?php
}
?>
</body>
</html>
mod_edit: