以下是引用片段: <?php
// store.php3 - by Florian Dittmer <dittmer@gmx.net> ?>
<HTML> <HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD> <BODY>
<?php // 如果提交了表单,代码将被执行:
if ($submit) {
// 连接到数据库 // (你可能需要调整主机名,用户名和密码)
MYSQL_CONNECT( "localhost", "root", "password"); mysql_select_db( "binary_data");
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$result=MYSQL_QUERY( "INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ". "VALUES (’$form_description’,’$data’,’$form_data_name’,’$form_data_size’,’$form_data_type’)");
$id= mysql_insert_id(); print "<p>This file has the following Database ID: <b>$id</b>";
MYSQL_CLOSE();
} else {
// 否则显示储存新数据的表单 ?>
<form method="post" action=" <?php echo $PHP_SELF; ?>" enctype="multipart/form-data"> File Description:<br> <input type="text" name="form_description" size="40"> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000"> <br>File to upload/store in database:<br> <input type="file" name="form_data" size="40"> <p><input type="submit" name="submit" value="submit"> </form>
<?php
}
?>
</BODY> </HTML> |