I have the following code that takes an image from a form & copies it to a directory on the server. It then resizes the image using ImageMagick's mogrify. I then want to take that image & insert it into the database, but I can't seem to find a way to get it to work.
I know that the copying of the image to the server & the resizing of the image work, but I can't find a way to insert it into the database properly so that I can display the image later.
Any help is greatly appreciated.
Thanks,
Jason Martin
<?
$dbuser = '****';
$dbhost = '*';
$dbpass = '*';
$dbname = '****';
MYSQL_CONNECT("localhost","nobody","");
mysql_select_db("opequon_motors");
?>
<?
if(isset($userfile)) {
srand(time());
$pid = (rand(111111,999999));
if(copy("$userfile", "/tmp/$pid.jpg"))
{
//print("file copied to /tmp<br>");
}
else
{
//print("file not copied to /tmp<br>");
}
exec("mogrify -density 72x72 -geometry 200x200! /tmp/$pid.jpg");
$data = fread(fopen("/tmp/$pid.jpg", "rw"), filesize($pid.jpg));
$result=MYSQL_QUERY("INSERT INTO images (bin_data,filename,filesize,filetype) "."VALUES ('$data','$userfile_name','$userfile_size','$userfile_type')");
$id= mysql_insert_id();
MYSQL_CLOSE();
} else {
print "<FORM ACTION=add_employee2.php enctype= 'multipart/form-data' METHOD=POST>
<INPUT TYPE=hidden NAME=MAX_FILE_SIZE VALUE=10000000>
<INPUT TYPE=FILE NAME=userfile><INPUT TYPE=SUBMIT VALUE=Mogrify></FORM>";
}
?>