Image storage and browsing case (LINUX+APACHE+PHP+MYSQL) _php Foundation
Source: Internet
Author: User
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 ("Cannot connect to the database");
$sql = "Select Filetype,filedata from image where id= ' $id '";
$rst = mysql_query ($sql, $server) or Die ("$sql query Error");
if ($row =mysql_fetch_row ($rst)) {
Header ("Content-type:"). $row [0]);
echo $row [1];
}
else{
echo "did not find the record";
}
Mysql_free_result ($rst);
Mysql_close ($server) or Die ("Cannot disconnect from the database server");
Break
Case ' list ':
? cmd=list
Show All pictures
Echo ' Echo ' Echo ' <body> ';
Echo ' <a href= '. $PHP _self. '? cmd=list ' > Show all Pictures </a> ';
echo "";
Echo ' <a href= '. $PHP _self. '? cmd=form ' > Upload picture </a> ';
$server = mysql_connect ("localhost", "Test", "") or Die ("Unable to connect to database Server");
mysql_select_db ("Test", $server) or Die ("Cannot connect to the database");
$sql = "Select id,description,filename,filetype,filesize from image";
$rst = mysql_query ($sql, $server) or Die ("$sql query Error");
while ($row =mysql_fetch_row ($rst)) {
echo "echo "Description:". $row [1]. "<br>";
echo "FileName:". $row [2]. "<br>";
echo "Type:". $row [3]. "<br>";
echo "Size:". $row [4]. "<br>";
Echo ' ';
}
Mysql_free_result ($rst);
Mysql_close ($server) or Die ("Cannot disconnect from the database server");
Echo ' </body> ';
Echo ' Break
Case ' form ':
?>
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service