Note the table structure used by this program is:
Use test;
CREATE TABLE Image (
ID int unsigned auto_increment primary key,
Description text,
FileName varchar (50),
FileSize int,
filetype varchar (50),
Filedata Longblob
);
*/
? Cmd={read|list|form|store}
Check the legality of the CMD parameter
Switch ($cmd) {
Case ' read ':
Break
Case ' list ':
Break
Case ' form ':
Break
Case ' Store ':
Break
Default
$cmd = ' list ';
Break
}
Switch ($cmd) {
Case ' read ':
? cmd=read&id={}
Read a picture
$server = mysql_connect ("localhost", "Test", "") or Die ("Unable to connect to database Server");
mysql_select_db ("Test", $server) or die ("Unable to connect to database");
$sql = "Select Filetype,filedata from image where";
$rst = mysql_query ($sql, $server) or Die ("error $sql query");
if ($row =mysql_fetch_row ($rst)) {
Header ("Content-type:".) $row [0]);
echo $row [1];
}
else{
echo "did not find this record";
}
Mysql_free_result ($rst);
Mysql_close ($server) or Die ("Cannot disconnect from database server");
Break
Case ' list ':
? cmd=list
Show All pictures
Echo '';
Echo ' <title>A case of image storage and browsing</title>';
Echo '';
echo ' Show all pictures ';
echo "";
echo ' upload image ';
$server = mysql_connect ("localhost", "Test", "") or Die ("Unable to connect to database Server");
mysql_select_db ("Test", $server) or die ("Unable to connect to database");
$sql = "Select id,description,filename,filetype,filesize from image";
$rst = mysql_query ($sql, $server) or Die ("error $sql query");
while ($row =mysql_fetch_row ($rst)) {
echo "";
echo "Description:". $row [1]. "
";
echo "File name:". $row [2]. "
";
echo "Type:". $row [3]. "
";
echo "Size:". $row [4]. "
";
Echo ';
}
Mysql_free_result ($rst);
Mysql_close ($server) or Die ("Cannot disconnect from database server");
Echo '';
Echo '';
Break
Case ' form ':
?>
<title>A case of image storage and browsing</title>
Break
Case ' Store ':
? cmd=store&description={}&file={}&file_size={}&file_type={}&file_name={}
Storing pictures
Echo '';
Echo ' <title>A case of image storage and browsing</title>';
Echo '';
echo ' Show all pictures ';
echo "";
echo ' upload image ';
$server = mysql_connect ("localhost", "Test", "") or Die ("Unable to connect to database Server");
mysql_select_db ("Test", $server) or die ("Unable to connect to database");
$data = Addslashes (Fread (fopen ($file, "R"), FileSize ($file)));
$sql = "INSERT into image (Description,filename,filetype,filesize,filedata)
VALUES (' $description ', ' ". BaseName ($file _name). "', ' $file _type ', $file _size, ' $data ')";
mysql_query ($sql, $server) or Die ("$sql execution error");
$id = mysql_insert_id ();
echo "The image effect you uploaded:
";
Echo ';
Mysql_close ($server) or Die ("Cannot disconnect from database server");
Echo '';
Echo '';
Break
}
?>
The above describes the Apachetomcat image storage and browsing an example of linux+apache+php+mysql, including the apachetomcat aspects of the content, I hope that the PHP tutorial interested in a friend helpful.