954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to view images using php

anybody i need the codes to display image. im stucked with it. Im already done doing the codes for uploading.
see it below..
i badly need it
<?php
// Create MySQL login values and
// set them to your login information.
$username = "root";
$password = "";
$host = "localhost";
$database = "db1";

// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}

// Select your database
mysql_select_db ($database);
// Make sure the user actually
// selected and uploaded a file

$target_path = "images/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
//echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
$sql = "INSERT INTO tb_product (product_image)values('$target_path')";
$result=mysql_query($sql);
mysql_close($link);
header ('Location: viewproducts.php');
} else{
echo "There was an error uploading the file, please try again!";
}

// Close our MySQL Link

?>

banmikko
Newbie Poster
10 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Hi

First you have to select that target path from the data base. Then you can display the image using the following code

<?=$targetpath?>

$targetpath should be the path you saved in the data base

ditty
Light Poster
41 posts since Sep 2007
Reputation Points: 10
Solved Threads: 3
 

the image is already saved in the database but when i used to view it with my viewproducts script, it was not shown. only the filename

banmikko
Newbie Poster
10 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 


try this.

<img src='<?php echo $targetpath;?>'>


If this code don't work, maybe you can post your viewproducts script here.

lyrico
Junior Poster in Training
94 posts since Dec 2010
Reputation Points: 33
Solved Threads: 15
 

guys,still doesnt worked!

banmikko
Newbie Poster
10 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

How does the resulting HTML source code look?
Did you really use $targetpath as variable name, or shouldn't ir read $target_path ?

smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: