Note that the table structure used in this program is:
Use test;
create table image(
filename varchar(50),
filesize int, filetype varchar(50),
filesize data longblob
));
*/
//?cmd={read|list|form|store}
//Check the validity of cmd parameters
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 ("Can't 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 " The record was not found";
}
mysql_free_result($rst);
mysql_close($server) or die("Unable to disconnect from the database server");
case 'list':
//?cmd=list
//Show all pictures
echo '';
echo '
An example of image storage and browsing';
echo '';
echo '< a href="' . $PHP_SELF . '?cmd=list">Show all images';
Form "& gt; upload pictures & lt;/a & gt; ';
$ Server = MySQL_CONNECT (" LocalHost "," Test "," ") or DIE (" Can't connect to the database 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" & lt; "hr & gt;";
echo "Description:". $ Row [1]. "& Echo" file name :" . $row[2] . "
";
echo "Type:" "
mysql_close($server) or die("Unable to disconnect from database server");
echo '';
echo '';
break;
case 'form':
? >
An example of image storage and browsing :
//?cmd=store&description={}&file={}&file_size={}&file_type={}&file_name={}
// Store picture h echo '& lt; html & gt;';
echo '& lt; head & lt; & lt; title & gt; picture storage and browsing an example & lt;/title & lt;/head & gt;'; Echo '& lt; body & gt;' ;
out PHP_SELF. '? CMD = FORM "& GT; uploaded pictures & lt;/a & gt;';
$ Server = MySQL_CONNECT (" LocalHost "," Test "," ") or DIE (" Can't connect to the database server ");
(( "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 effect of the picture you uploaded:
";
echo '
';
mysql_close($server) or die("Unable to disconnect from the database server");
echo '< /body>';
echo '