10 Replies - 10645 Views - Last Post: 17 August 2009 - 12:37 AM Rate Topic: -----

#1 fakxitnicolai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-August 09

Image not displaying from mysql using php

Post icon  Posted 13 August 2009 - 06:11 PM

i have a problem in displaying the image:
here's how i uploaded it:
<?php 
error_reporting (E_ALL ^ E_NOTICE);

$Submit = $_POST['Submit'];

if($Submit == 'Upload')
{
$pid = base64_decode($_GET['id']);

if(isset($_FILES['uploaded_file']))
{
if($_FILES['uploaded_file']['error'] == 0)
	{$Link = mysqli_connect("localhost","root","", "");
	if(mysqli_connect_errno()){
		die("Mysql connection failed:".mysqli_connect_errno());
		}
		$name = mysqli_real_escape_string($Link, $_FILES['uploaded_file']['name']);
		$data = mysqli_real_escape_string($Link, file_get_contents($_FILES ['uploaded_file']['tmp_name']));
		
		$query = "INSERT INTO pix(pid, title, imgdata) values('$pid', '$name', '$data')";
		
		$result = mysqli_query($Link, $query);
		
		
		
		if($result)
		{
$asd = "Your file was successfully added!";
$alert = base64_encode($asd);
header("Location:registration.php?alert=$alert");
exit();
		}
		else
		{
		$asd = "Error! An error occurred while the file was being uploaded.
		Error code:".rand()."";
$alert = base64_encode($asd);
header("Location:picul.php?alert=$alert");
exit();
		}
		mysqli_close($Link);
}
else
{
	$asd = "Error! A file was not sent! Try to upload again.Error code:".rand()."";
$alert = base64_encode($asd);
header("Location:picul.php?alert=$alert");
exit();
}
}		
}


if($Submit == 'Cancel')
{
$pid = base64_encode($_GET['id']);
header("Location:done.php?id=$pid");
exit();
}


here's how i retrieve it:

<input name="image" type="image" src="asdf.php?imgid=<?Php echo $form_no; ?>" />
 



this is the asdf.php
i tried two kind of coding here's the first:
$id = $_REQUEST['imgid'];

$Link = mysqli_connect("localhost","root","tupi", "amyak_maleh");
			if (!$Link)
			  {
			  trigger_error("Could not connect", E_USER_ERROR );
			  }
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{

$query = mysqli_query($Link, "SELECT imgdata FROM pix WHERE pid= '$id' ");
$row = mysqli_fetch_assoc($query);
$content = $row['imgdata'];


header('Content-type: image/jpg');
echo $content;




here's the next one:
 header('Content-Type: image/jpeg');
   //$id = $_GET['imgid'];
   $id = isset($_REQUEST['imgid']) ? $_REQUEST['imgid'] : false;
	
	
   if($id)
	{
	  $Link = mysqli_connect("localhost","root","tupi", "amyak_maleh");
	  if(mysqli_connect_errno())
	  {
		 die("Mysql connection failed:".mysqli_connect_errno());
	}
	
	 $result = mysqli_query($Link, "SELECT imgdata from pix where pid = {$id} ");
   if(is_resource($result))
	  {
		 $row = mysql_fetch_assoc($result);
		echo $row['imgdata'];
		}
		else
		{
		echo "no picture";
		}
	 }	
	 else
		{
		echo "no id";
		}



both are not working..somebody help me please.. which one should i use? anyone could suggest?

Is This A Good Question/Topic? 0
  • +

Replies To: Image not displaying from mysql using php

#2 peter yianni  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 310
  • Joined: 04-June 09

Re: Image not displaying from mysql using php

Posted 13 August 2009 - 08:06 PM

View Postfakxitnicolai, on 13 Aug, 2009 - 05:11 PM, said:

i have a problem in displaying the image:
here's how i uploaded it:
<?php 
error_reporting (E_ALL ^ E_NOTICE);

$Submit = $_POST['Submit'];

if($Submit == 'Upload')
{
$pid = base64_decode($_GET['id']);

if(isset($_FILES['uploaded_file']))
{
if($_FILES['uploaded_file']['error'] == 0)
	{$Link = mysqli_connect("localhost","root","", "");
	if(mysqli_connect_errno()){
		die("Mysql connection failed:".mysqli_connect_errno());
		}
		$name = mysqli_real_escape_string($Link, $_FILES['uploaded_file']['name']);
		$data = mysqli_real_escape_string($Link, file_get_contents($_FILES ['uploaded_file']['tmp_name']));
		
		$query = "INSERT INTO pix(pid, title, imgdata) values('$pid', '$name', '$data')";
		
		$result = mysqli_query($Link, $query);
		
		
		
		if($result)
		{
$asd = "Your file was successfully added!";
$alert = base64_encode($asd);
header("Location:registration.php?alert=$alert");
exit();
		}
		else
		{
		$asd = "Error! An error occurred while the file was being uploaded.
		Error code:".rand()."";
$alert = base64_encode($asd);
header("Location:picul.php?alert=$alert");
exit();
		}
		mysqli_close($Link);
}
else
{
	$asd = "Error! A file was not sent! Try to upload again.Error code:".rand()."";
$alert = base64_encode($asd);
header("Location:picul.php?alert=$alert");
exit();
}
}		
}


if($Submit == 'Cancel')
{
$pid = base64_encode($_GET['id']);
header("Location:done.php?id=$pid");
exit();
}


here's how i retrieve it:

<input name="image" type="image" src="asdf.php?imgid=<?Php echo $form_no; ?>" />
 



this is the asdf.php
i tried two kind of coding here's the first:
$id = $_REQUEST['imgid'];

$Link = mysqli_connect("localhost","root","tupi", "amyak_maleh");
			if (!$Link)
			  {
			  trigger_error("Could not connect", E_USER_ERROR );
			  }
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{

$query = mysqli_query($Link, "SELECT imgdata FROM pix WHERE pid= '$id' ");
$row = mysqli_fetch_assoc($query);
$content = $row['imgdata'];


header('Content-type: image/jpg');
echo $content;




here's the next one:
 header('Content-Type: image/jpeg');
   //$id = $_GET['imgid'];
   $id = isset($_REQUEST['imgid']) ? $_REQUEST['imgid'] : false;
	
	
   if($id)
	{
	  $Link = mysqli_connect("localhost","root","tupi", "amyak_maleh");
	  if(mysqli_connect_errno())
	  {
		 die("Mysql connection failed:".mysqli_connect_errno());
	}
	
	 $result = mysqli_query($Link, "SELECT imgdata from pix where pid = {$id} ");
   if(is_resource($result))
	  {
		 $row = mysql_fetch_assoc($result);
		echo $row['imgdata'];
		}
		else
		{
		echo "no picture";
		}
	 }	
	 else
		{
		echo "no id";
		}



both are not working..somebody help me please.. which one should i use? anyone could suggest?



when u say not working whats happening do u get a error on the screen

tyr this echo $row['$result'];

This post has been edited by peter yianni: 13 August 2009 - 08:12 PM

Was This Post Helpful? 0
  • +
  • -

#3 fakxitnicolai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-August 09

Re: Image not displaying from mysql using php

Posted 13 August 2009 - 09:11 PM

the picture is not displaying.. in the img tag..
Was This Post Helpful? 0
  • +
  • -

#4 peter yianni  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 310
  • Joined: 04-June 09

Re: Image not displaying from mysql using php

Posted 13 August 2009 - 09:28 PM

View Postfakxitnicolai, on 13 Aug, 2009 - 08:11 PM, said:

the picture is not displaying.. in the img tag..



did u try this

change from

echo $row['imgdata'];

to


echo $row['$result'];
Was This Post Helpful? 0
  • +
  • -

#5 fakxitnicolai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-August 09

Re: Image not displaying from mysql using php

Posted 13 August 2009 - 09:36 PM

yes it tried it.. still not working.. there's no sign of error, but if i open the file in the browser asdf.php there's a dialog box that will appear and prompt if i'll save open or cancel it.. its like downloading the file.
Was This Post Helpful? 0
  • +
  • -

#6 peter yianni  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 310
  • Joined: 04-June 09

Re: Image not displaying from mysql using php

Posted 13 August 2009 - 10:08 PM

View Postfakxitnicolai, on 13 Aug, 2009 - 08:36 PM, said:

yes it tried it.. still not working.. there's no sign of error, but if i open the file in the browser asdf.php there's a dialog box that will appear and prompt if i'll save open or cancel it.. its like downloading the file.



u have to save your page as .php
otherwise u get them errors

r u using local host sounds like it not set up correctly

This post has been edited by peter yianni: 13 August 2009 - 10:10 PM

Was This Post Helpful? 0
  • +
  • -

#7 fakxitnicolai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-August 09

Re: Image not displaying from mysql using php

Posted 13 August 2009 - 10:43 PM

yes. i am using a localhost..

whats wrong?
and another thing, when i use this:
echo $row['imgdata'];




there shows the sets of strings.. what should i do?
how to convert those strings? do i need to convert it?

This post has been edited by fakxitnicolai: 13 August 2009 - 10:51 PM

Was This Post Helpful? 0
  • +
  • -

#8 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Image not displaying from mysql using php

Posted 14 August 2009 - 11:59 PM

have you tried to encode it $content = base64_decode($row['imgdata']);

and also this link will help you :)
Upload and to mysql database
Was This Post Helpful? 0
  • +
  • -

#9 fakxitnicolai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-August 09

Re: Image not displaying from mysql using php

Posted 16 August 2009 - 04:59 PM

View Postnoorahmad, on 14 Aug, 2009 - 10:59 PM, said:

have you tried to encode it $content = base64_decode($row['imgdata']);

and also this link will help you :)
Upload and to mysql database



yes.. i tried to decode it.. nothing happen.. is there something wrong with my codes?..
Was This Post Helpful? 0
  • +
  • -

#10 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Image not displaying from mysql using php

Posted 16 August 2009 - 11:45 PM

can you past your current code? :)
Was This Post Helpful? 0
  • +
  • -

#11 it_1  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 10-August 09

Re: Image not displaying from mysql using php

Posted 17 August 2009 - 12:37 AM

hi,


try this,

php code:

first you shold print it in one php page,

for example download.php

$sql="select imgdata(ur image data stored column name) from table_name where condtions;
$sql_result=mysql_query($sql);
$row=mysql_fetch_assoc($sql_result);
echo $row['imgdata'];


the call it in your webpage like,

<img src="download.php"/>
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1