Apachetomcat picture storage and browsing a case of linux+apache+php+mysql

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 ("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.

  • Related Article

    Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.