Php stores the image in binary format into the mysql database and displays the implementation code. Copy the code of the php code that saves the image to the database: If ($ Picture! None) {$ PSizefilesize ($ Picture); $ mysqlPictureaddslashes (fread (fopen ($ Picture, r), $ PSize // php code for saving images to the database
The code is as follows:
If ($ Picture! = "None "){
$ PSize = filesize ($ Picture );
$ MysqlPicture = addslashes (fread (fopen ($ Picture, "r"), $ PSize ));
Mysql_connect ($ host, $ username, $ password) or die ("Unable to connect to SQL server ");
@ Mysql_select_db ($ db) or die ("Unable to select database ");
Mysql_query ("insert into Images (Image) VALUES ($ mysqlPicture)") or die ("Cant Perform Query ");
} Else {
Echo "You did not upload any picture ";
}
// Code for reading images in the database using the img tag
The code is as follows:
Mysql_connect ($ host, $ username, $ password) or die ("Unable to connect to SQL server ");
@ Mysql_select_db ($ db) or die ("Unable to select database ");
$ Result = mysql_query ("SELECT * FROM Images") or die ("Cant Perform Query ");
While ($ row = mysql_fetch_object ($ result )){
Echo "PicNum"> ";
// The code for the secoed. php file is as follows:
$ Result = mysql_query ("SELECT * FROM Images WHERE PicNum = $ PicNum") or die ("Cant perform Query ");
$ Row = mysql_fetch_object ($ result );
Header ("Content-type: image/gif ");
Echo $ row-> Image;
The example code is as follows: If ($ Picture! = "None") {$ PSize = filesize ($ Picture); $ mysqlPicture = addslashes (fread (fopen ($ Picture, "r"), $ PSize...