Apachetomcat: Linux + Apache + PHP + MySQL

Source: Internet
Author: User
Apachetomcat: apachetomcat image storage and browsing: Linux + Apache + PHP + MySQL: note that the table structure used in this program is: usetest; createtableimage (idintunsignedauto_incrementprimarykey, descriptiontext, filename note that the table structure used in 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 validity 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 an image
$ Server = mysql_connect ("localhost", "test", "") or die ("unable to connect to the 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 ("$ SQL query error ");
If ($ row = mysql_fetch_row ($ rst )){
Header ("Content-Type:". $ row [0]);
Echo $ row [1];
}
Else {
Echo "this record is not found ";
}
Mysql_free_result ($ rst );
Mysql_close ($ server) or die ("unable to disconnect from database server ");
Break;
Case 'List ':
//? Cmd = list
// Display all images
Echo'';
Echo' An example of image storage and browsing';
Echo'';
Echo 'show all images ';
Echo "";
Echo 'upload image ';
$ Server = mysql_connect ("localhost", "test", "") or die ("unable to connect to the 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 ("$ SQL query error ");
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 ("unable to disconnect from database server ");
Echo'';
Echo'';
Break;
Case 'form ':
?>

An example of image storage and browsing




Break;
Case 'store ':
//? Cmd = store & description ={}& file ={} & file_size ={} & file_type ={} & file_name = {}
// Store images
Echo'';
Echo' An example of image storage and browsing';
Echo'';
Echo 'show all images ';
Echo "";
Echo 'upload image ';
$ Server = mysql_connect ("localhost", "test", "") or die ("unable to connect to the 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 "effect of the image you uploaded:
";
Echo '';
Mysql_close ($ server) or die ("unable to disconnect from database server ");
Echo'';
Echo'';
Break;
}
?>

The above section describes how to store and browse apachetomcat images in Linux + Apache + PHP + MySQL, including apachetomcat, and hopes to help anyone who is interested in PHP tutorials.

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.