Php saves images to the mysql tutorial database and shows them on the webpage. Generally, it does not need to save the breakthrough to the database. It is very troublesome whether it is remote backup or something, except for special requirements.
Php saves images to the mysql tutorial database and shows them on the webpage. Generally, it does not need to save the breakthrough to the database. It is very troublesome whether it is remote backup or something, except for special requirements.
// Php code for saving the image 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;