PHP saves uploaded images to the database and displays the code
PHP Tutorials Save uploaded diagrams to the database tutorial and display the code
Connect to Database
$errmsg = "";
if (! @mysql tutorial _connect ("localhost", "root", "")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db ("DB1");
$q = <<
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) < 149000) {
mysql_query ("INSERT into PIX (title, Imgdata) VALUES (" ".)
$_request[whatsit].
"", "".
$image.
"")");
} else {
$errmsg = "Too large!";
}
}
Find out about latest image
$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";
Put up a picture of our training centre
$instr = fopen (".. /wellimg/ctco.jpg "," RB ");
$bytes = Fread ($instr, FileSize (". /wellimg/ctco.jpg "));
}
If the image request, send out the image
if ($_request[gim] = = 1) {
Header ("Content-type:image/jpeg");
Print $bytes;
Exit ();
}
?>
Upload an image to a database
Here's the latest picture
Upload a new picture and title
http://www.bkjia.com/PHPjc/630871.html www.bkjia.com true http://www.bkjia.com/PHPjc/630871.html techarticle php Saves the uploaded diagram to the database and displays the code PHP tutorial to save the uploaded diagram to the database tutorial and display the code/Connect to databases $errmsg =; if (! @mysql tutorial _connect (loc ...