0

ok so my development folder is in xammp htdocs (php codes)
i am trying to insert an image to a table and when i display it on the php pages, it does not show why is this??
i used the absolute and relative path both. the images i need to use are saved in a folder called images in my development folder as well.

why is this????

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by zinnqu
0

I just got mine to work.. try this

<?php
$host = "localhost";
$user = "user";
$base = "database";
$pass = "PASSWORDDELETED";
$dirself = $_SERVER['PHP_SELF'];
$req = @mysql_connect($host, $user, $pass);
$cnx = @mysql_select_db($base) or die("you f'ed up!");
$ds = date(dmy);
if ($cnx) {
echo '<html>'.
'<head />'.
'<body>'.
'<form action="'.$dirself.'" enctype="multipart/form-data" method=post >'.
'Desription<br />'.
'<textarea name=comment></textarea>'.
'<p />'.
'<input type=file name=file id="file">'.
'<input type=hidden name=maxsize value="2400000">'.
'<input type=hidden name=action value="record_insert">'.
'<input type=submit value="submit record">'.
'</form>'.
'</body>'.
'</html>';

If ($_POST['action'] == 'record_insert')
{
$size = filesize($_FILES['file']['tmp_name']);
$type = $_FILES['file']['type'];
$name= $ds.$_FILES['file']['name'];
$comment =  $_POST['comment'];
$max = $_POST['maxsize'];
$target_path = $_FILES['file']['tmp_name'];
$filer=file_get_contents($target_path);
$handle = fopen($target_path, "r");
$pure = addslashes(fread($handle, filesize($target_path)));
$sql = "INSERT INTO imgdb ( image_name, image_size, image_type, image_desc, image)".
 "VALUES ('$name','$size','$type','$comment','$pure')";
$res = @mysql_query($sql) or die(mysql_error());
If (!$res) {echo "oops I could not upload!";}
header('index.php');
}
} else {
echo mysql_error();
}
?>

Just make sure that your database has blob type for the image itself. the rest can be modded to allow for what you need in your db.

0

the other part of the issue that you might have is just making a call to an image tag.

<?php
echo '<table><tr><td>';
echo '<img src="pic.jpg">';
echo '</td></tr></table>';
?>

to recall it from the db that i gave an example of is:
image.php

<?php

if (isset ($_GET['image_id']) )
  $id = intval ($_GET['image_id']);
  
     $hote = 'localhost';
     $base = 'database';
     $user = 'user'
     $pass = 'PASSWORDDELETED'
     $cnx = mysql_connect ($hote, $user, $pass) or die(mysql_error ());
     $ret = mysql_select_db ($base) or die (mysql_error ());
  $req = "SELECT image_id, image_type, image ".
              "FROM testblob WHERE image_id = ".$id;
  $ret = mysql_query ($req) or die (mysql_error ());
  $col = mysql_fetch_row ($ret);
  if ( !$col[0])
  (
    echo "the id of the picture does not exist";
  ) else
  (
    header ("Content-type : ".$col[1];
    echo $col[2];
  ) else
  (
    echo "the id of the picture is not valid";
  )
?>

to call it simply use <img src="image.php?id=1" alt="web stored image">

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.