only get a red cross

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

devmatch
Forum Newbie
Posts: 19
Joined: Thu Mar 27, 2003 3:58 am

only get a red cross

Post 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
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

Could you tell us more :?: Maybe, you should include your script in your post.
devmatch
Forum Newbie
Posts: 19
Joined: Thu Mar 27, 2003 3:58 am

scripts...

Post 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&nbsp;" );
		    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&nbsp;" );
		        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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
devmatch
Forum Newbie
Posts: 19
Joined: Thu Mar 27, 2003 3:58 am

still not working

Post 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;)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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&#1111;"product_image"]);
devmatch
Forum Newbie
Posts: 19
Joined: Thu Mar 27, 2003 3:58 am

testing,testing,testing...

Post 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 :oops: "), filesize($product_image)));
[/b]
Last edited by devmatch on Thu Jun 12, 2003 9:44 am, edited 1 time in total.
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

What's the code that puts the image's data into the database?
devmatch
Forum Newbie
Posts: 19
Joined: Thu Mar 27, 2003 3:58 am

sorry for ymy problems:(

Post 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
:(
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

Code: Select all

if ( $valid_image )
$productInfo&#1111;"product_image"] = addslashes(fread(fopen($product_image, "r"), filesize($product_image)));
&#125;
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&#1111;"product_image"]);
With

Code: Select all

echo stripslashes($row&#1111;"product_image"]);
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

And I just realized, you might also need to fopen() the $product_image as "rb", not just "r".
devmatch
Forum Newbie
Posts: 19
Joined: Thu Mar 27, 2003 3:58 am

using windoof

Post by devmatch »

it is possible to change the user rights from r to rw???
devmatch
Forum Newbie
Posts: 19
Joined: Thu Mar 27, 2003 3:58 am

Re: using windoof

Post by devmatch »

devmatch wrote:it is possible to change the user rights from r to rw in windows???
devmatch
Forum Newbie
Posts: 19
Joined: Thu Mar 27, 2003 3:58 am

find my solution script:)

Post 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:

Code: Select all

tags added[/size]
Post Reply