Hi,
I can see your point, but I deliberately wanted the images to be stored in database. I've spent the past three weeks with this little mini project at the back of my mind.
I have the images displaying on the screen now perfectly fine, but only when I append the 'id' to the url in the browser (/show_image.php?id=20) and it should be being passed straight onto it by the script so when the user clicks the 'show' button it does it automatically.........but it doesnt!
heres the modified upload code:
<?php
mysql_connect("xxxxx", "xxxxx", "xxxxx");
mysql_select_db("xxxxx");
// code that will be executed if the form has been submitted:
if ((isset($_POST['submit']))&&(isset($_FILES['form_data']))) {
upload();
} else {
show_form();
}//end if
function upload() {
//define variables
$image_file = '';
$image_desc = '';
$type = '';
$size = 0;
$name = '';
$image_file = $_FILES['form_data']['tmp_name'];
$image_desc = $_POST['form_description'];
$type = $_FILES['form_data']['type'];
$size = $_FILES['form_data']['size'];
$name = $_FILES['form_data']['name'];
$data = fread(fopen($image_file, "r"), filesize($image_file));
$data = addslashes($data);
$result="INSERT INTO binary_data VALUES (NULL,'". $image_desc ."','". $data ."','". $name ."','". $size ."','". $type ."')";
@mysql_query($result) or die(mysql_error());
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
//show the form again to load the next image
show_form();
}
function show_form()
{
// else show the form to submit new data:
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data" size="40">
<p>
<input type="submit" name="submit" value="submit">
<input type="button" name="move" value="Show" onClick="javascript:window.location='show_image.php';">
<a href="show_image.php">view image</a> </p>
</form>
<?php
}
?>
and heres the modified show_image code:
<?php
mysql_connect("xxxxx", "xxxxx", "xxxxx");
mysql_select_db("xxxxx");
//check to see if the id is passed
if(isset($_GET['id'])) {
$id=$_GET['id'];
$query = mysql_query("SELECT bin_data, filetype FROM binary_data WHERE id='". $id ."'");
//echo $query;
$result = ($query);
$row = mysql_fetch_array($result);
{
$data = $row['bin_data'];
$type = $row['filetype'];
}
if ($type=="pjpeg") $type = "jpeg";
Header( "Content-type: $type");
echo $data;
}
?>
Sorry to be a pain, and appologise for not taking your advice about the location of the images.
Any ideas would be awsome!
many thanks
Mark