PHP图片上传程序设计

<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>
<?php
 
if (isset($_POST['submit'])) {
$form_description = $_POST['form_description'];
$form_data_name = $_FILES['form_data']['name'];
$form_data_size = $_FILES['form_data']['size'];
$form_data_type = $_FILES['form_data']['type'];
$form_data = $_FILES['form_data']['tmp_name'];
  
$connect = MYSQL_CONNECT( "localhost", "root", "123456") or die("Unable to connect to MySQL server");
mysql_select_db( "test") or die("Unable to select database");
 
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
 
//echo "mysqlPicture=".$data;

$result=MYSQL_QUERY( "INSERT INTO ccs_image (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: <a href='show.php?id=$id'><b>$id</b></a>";

MYSQL_CLOSE();


} else {

?>
 <center>
<form method="post" action="http://localhost/upload.php" enctype="multipart/form-data">
File Description:
<input type="text" name="form_description" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000"> <br>
File to upload/store in database:
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
 </center>
<?php
}
?>
</BODY>
</HTML>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值