PHP code to save pictures to the database
Copy Code code 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 upload no picture";
}
Code to read a picture in a database with an IMG tag
Copy Code code 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 ">";
//If the secoed.php file code is
$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;