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.