Hello All,
What I'm trying to do is take an image that was taken from a security cam and send it via http "post" to a php script that will file that image in a mysql database. I'm able to send the image I want through the built in cam software but am unable to get the server side script working to take the image and file it in the database.
Here's what I have so far:
<?php
// Connect to database
$errmsg = "";
if (! @mysql_connect("76.163.xxx.xxx", "xx_xxxx", "xxxxxxx")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db("test");
//
$q = <<<CREATE
create table pix (
pid int primary key not null auto_increment,
title text,
imgdata longblob)
CREATE;
@mysql_query($q);
// Insert any new image into database
if ($_REQUEST[completed] == 1) {
//
move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
$instr = fopen("latest.img","rb");
$image = addslashes(fread($instr,filesize("latest.img")));
if (strlen($instr) < 149000000) {
mysql_query ("insert into pix (title, imgdata) values (\"".
$_REQUEST[whatsit].
"\", \"".
$image.
"\")");
} else {
$errmsg = "Too large!";
}
}
//
$gotten = @mysql_query("select * from pix order by pid desc limit 1");
if ($row = @mysql_fetch_assoc($gotten)) {
$title = htmlspecialchars($row[title]);
$bytes = $row[imgdata];
} else {
$errmsg = "There is no image in the database yet";
$title = "no database image available";
}
//
if ($_REQUEST[gim] == 1) {
header("Content-type: image/jpeg");
print $bytes;
exit ();
}
?>
Any help is appreciated!
Thanks,
Danny