本文实例讲述了PHP实现上传文件并存进数据库的方法。分享给大家供大家参考。具体如下:
PHP;">
PHP
if(!isset($_REQUEST['id']) or $_REQUEST['id']=="") die("error: id none");
$id = $_REQUEST['id'];
//定位记录,读出
$conn=MysqL_connect("localhost","root","admin");
if(!$conn) die("error: MysqL connect Failed");
MysqL_select_db("nokiapaymentplat",$conn);
$sql = "select * from receive where id=$id";
$result = MysqL_query($sql,$conn);
if(!$result) die("error: MysqL query");
$num=MysqL_num_rows($result);
if($num<1) die("error: no this recorder");
$data = mysql_result($result,"file_data");
$type = mysql_result($result,"file_type");
$name = mysql_result($result,"file_name");
mysql_close($conn);
//先输出相应的文件头,并且恢复原来的文件名
header("Content-type:$type");
header("Content-Disposition: attachment; filename=$name");
echo $data;
?>
PHP;">
PHP
if(!isset($_REQUEST['id']) or $_REQUEST['id']=="") die("error: id none");
$id = $_REQUEST['id'];
//定位记录,$conn);
$sql = "select file_name,file_size from receive where id=$id";
$result = MysqL_query($sql,$conn);
if(!$result) die(" error: MysqL query");
//如果没有指定的记录,则报错
$num=MysqL_num_rows($result);
if($num<1) die("error: no this recorder");
//下面两句程序也可以这么写
//$row=mysql_fetch_object($result);
//$name=$row->name;
//$size=$row->size;
$name = MysqL_result($result,"file_name");
$size = MysqL_result($result,"file_size");
MysqL_close($conn);
echo "
上传的文件的信息:"; echo "
The file's name - $name"; echo "
The file's size - $size"; echo "
附件"; ?>
上传的文件的信息:"; echo "
The file's name - $name"; echo "
The file's size - $size"; echo "
附件"; ?>
PHP;">
显示上传文件信息";
}
else {
echo "你没有上传任何文件";
}
?>