Upload | data | database If you have any questions please contact me: http://www.webjx.com web@webjx.com
Reprint please indicate the source
Today to teach you how to use the PHP implementation of the image uploaded to the MySQL database. In this tutorial we need to create 3 PHP files:
readdir.php-code to put the picture in the database
Image.php-code to display the actual picture
View.php-code to show how you call a picture in a database
1. Create a database
CREATE TABLE ' images ' (
' Imgid ' INT not NULL auto_increment,
' Sixfourdata ' longtext not NULL,
PRIMARY KEY (' Imgid ')
);
READDIR. Php
Specific content:
?
$DBCNX = mysql_connect ("localhost", "username", "password");
mysql_select_db ("Base64imgdb");
?>
' We need to open a directory
"./"
The ' readdir.php file is located in this directory:
$path = "./";
$dir_handle = Opendir ($path) or Die ("Unable to open Directory $path");
Here are the more difficult parts, we need to study it: the image classification, and read out the use of some data
Read the code for the picture: image.php
This code is more difficult, we have to take a good look at
?
$DBCNX = mysql_connect ("localhost", "username", "password");
mysql_select_db ("Base64imgdb");
?>
We read out the code used by the picture image.php?img=x:
?
$img = $_request["img"];
?>
Then we need to connect to the database and read out
?
$result = mysql_query ("SELECT * from Images WHERE imgid=".) $img. "");
if (!$result) {
Echo ("<b> request Error:".) Mysql_error (). "</b>");
Exit ();
}
while ($row = Mysql_fetch_array ($result)) {
$imgid = $row["Imgid"];
$encodeddata = $row["Sixfourdata"];
}
?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.