Jump to content

Image is not displaying


avirup

Recommended Posts

<?php require_once("session_con.php");
require_once("functions.php"); 
confirm_logged_in();
//connect to the database server and the database  
dbconnect();
//session data fetching for test
$id= $_SESSION['suid'];
//echo $id;
//Get data from the prevoius page
//$id = $_GET['user_id'];
//echo $id;
//Checking the get data is valid or empty
if(!$id)
{
echo "No image available";
}
else
{
//Select image from the database
$sql="SELECT  * FROM `user_image` WHERE `user_id` ='".$id."';";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
$fdata = $row['FileData'];
$ftype = $row['MimeType'];
$fname = $row['FileName'];
}
//setting the header information to display the image
header('Content-type: $ftype');
echo $fdata;

?>

Omage is not displaying when i m running the page...
save option is coming...instead of displaying the image...


can anybody correct the code...coz...it's showing sometimes peculier data and last line is 
header output send already...thank You.

Link to comment
Share on other sites

The script used to set header and display image content,

<?php
//setting the header information to display the image
header('Content-type: $ftype');
echo $fdata;
?>

 

has to be moved to the else part because the error msg  ("No image available") can't be displayed if session doesn't exist.

 

Check the script by moving the above script to the else part whether it shows the error - "No image available".

 

 

 

Link to comment
Share on other sites

Thank for the reply..!!!

 

Yea I have put the last part in the else part..session is exist and thus "No image " error is not echoing.Instead of that save the file dialog box is opening .

 

when I save and open the file some peculiar data is showing there.

 

So what I will do now!!

Link to comment
Share on other sites

I have done few changes in my code...

as previously I was fetching the userid from the session

now I wanna display the image linking from another page

 

disaply.php

<div id="photo">
      <img src="getimage.php?user_id=<?php print $user_id; ?>" width="162" height="156" /></div>

and now the getimage.php code

<?php require_once("session_con.php");
require_once("functions.php"); 
confirm_logged_in();
//connect to the database server and the database  
dbconnect();

//Get data from the prevoius page
$id = $_GET['user_id'];
//I also tried echo to display the user_id...now its not coming also

//Checking the get data is valid or empty
if(!$id)
{
echo "Image is not available";
}
else
{
//Select image from the database
$sql="SELECT  * FROM `user_image` WHERE `user_id` ='".$id."';";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
$fdata = $row['FileData'];
$ftype = $row['MimeType'];
$fname = $row['FileName'];

//setting the header information to display the image
header('Content-type: $ftype');
echo $fdata;
}
?>

 

Can anybody help me...now..please..!!!

It's over a week I am trying...!!!

Thank you..in advance!!!

Link to comment
Share on other sites

Ahhhh I think I know what it is. Take a close look at header('Content-type: $ftype'); you're tossing a variable in a set of single quotes. change the ' to " like this header("Content-type: $ftype");

 

Additionally you can also do this: header('Content-type: ' . $ftype);

Link to comment
Share on other sites

Yeah, this is a weird problem you're having. One last thing I can think about is the mime type.

 

What is the mime? image/jpeg image/png?

 

can you add

 

die( $row['MimeType'] );

 

After

 

$fdata = $row['FileData'];
$ftype = $row['MimeType'];
$fname = $row['FileName'];

 

And post what that says. The only, last thing I can think of then is an invalid mime type...

And if you posted that link to show us what's going on we can't see it since it's on your localhost. Can you post an example on the web at all?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.