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????

Recommended Answers

All 2 Replies

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.

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">

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.