Jump to content

Recommended Posts

Hey there all. Excuse me as I am new to PHP and exceptionally dof.

 

I am trying to pull an image out of an mssql database and display it. The problem is it keeps coming out as a bunch of garbage. What I gather is that i need to have a separate page that checks if its an image and then prints it or something to the main page ? Anyone have an example of this.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/93174-solved-pull-an-image-out-of-a-database/
Share on other sites

OK, no one answered so I will try elaborate some more. Basically I need to pull out related images and display them in my main page. The problem is that I either get no image coming back ( just the image placeholder ), or I can get a bunch of hex garbage to come back. Here is the mini.php page i use :

 

<?php #mini.php

// Used to locate record based on ID number

// Should pass image back and display

require_once( "./common_db.php" );

 

if ( ! $link_id = db_connect($default_dbname) ) {

die( "connection to db failed" );

}

 

$id = $_GET['id'];

$q = "select Photo1 from $user_tablename where ID = $id";

 

if ( ! $image_result = mssql_query($q,$link_id) ) {

die( "error with query: $q" );

}

 

if ( mssql_num_rows( $image_result ) < 1 ) {

die( "no results found" );

}

 

$image = mssql_fetch_assoc( $image_result );

 

//echo $image;

 

header("content-type image/jpeg");

echo $image['Photo1'];

 

//Print $image;

//echo($image);

 

?>

 

Here is the part of code that calls mini.php

 

 

while($query_data = mssql_fetch_array($result))

{

$ID = $query_data["ID"];

$StreetAddress = $query_data["Street_Address"];

$Price = $query_data["Price"];

$Zone1 = $query_data["Zone1"];

//$Photo1 = $query_data["Photo1"];

//$Photo2 = $query_data["Photo2"];

//$Photo3 = $query_data["Photo3"];

//$Photo4 = $query_data["Photo4"];

 

echo "<TR>\n";

echo "<TD WIDTH=\"111\" ALIGN=\"LEFT\"><font size=\"2\">$ID</font></TD>\n";

echo "<TD WIDTH=\"128\" ALIGN=\"LEFT\"><font size=\"2\">$StreetAddress</font></TD>\n";

echo "<TD WIDTH=\"121\" ALIGN=\"LEFT\"><font size=\"2\">$Price</font></TD>\n";

echo "<TD WIDTH=\"67\" ALIGN=\"LEFT\"><font size=\"2\">$Zone1</font></TD>\n";

echo "<TD WIDTH=\"46\" ALIGN=\"LEFT\"><img src='mini.php?id=$ID'></TD>\n"; // Calls mini.php which should locate the image by ID number and pass it back with the correc header    // echo "<TD WIDTH=\"46\" ALIGN=\"LEFT\"><img src='D:\Mike Misc\Graphics\Wallpapers\1.jpg'></TD>\n";

// echo "<TD WIDTH=\"46\" ALIGN=\"LEFT\"><img src=\"$Photo1\"/></TD>\n";

// echo "<TD WIDTH=\"48\" ALIGN=\"LEFT\"><font size=\"2\">$Photo2</font></TD>\n";

// echo "<TD WIDTH=\"93\" ALIGN=\"LEFT\"><font size=\"2\">$Photo3</font></TD>\n";

// echo "<TD WIDTH=\"243\" ALIGN=\"LEFT\"><font size=\"2\">$Photo4</font></TD>\n";

 

echo "</TR>\n";

}

 

 

Any  ideas why it doesnt work. I am lost.

Hi,

I had the same problem you are having of uploading an image to a mssql database and then downloading it for viewing.

The issue was resolved and you can find my solution here.

http://www.phpfreaks.com/forums/index.php/topic,146750.0.html

 

The problem is the way you upload the data, there is an article in the thread that explains this.

Hope this helps!

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.