利用PHP如何将声音或文本文件存入ORACLE数据里,又如何取出?

xxyujin 2002-02-25 03:16:56
利用PHP如何将声音或文本文件存入ORACLE数据里,又如何取出?谢谢
...全文
130 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxyujin 2002-02-28
  • 打赏
  • 举报
回复
整理:
存入图片
<form name="form1" method="post" action="<?echo $path_info?>" enctype="multipart/form-data">
<p>
<input type="text" name="id">
</p>
<p>
<input type="text" name="title">
</p>
<p>
<input type="file" name="fileinput">
</p>
<p> <input type="submit" name="Submit" value="Submit">
</p>
</form>
<?
mysql_connect("localhost","root","123") or die("connect error");
mysql_select_db("yujin");
if($Submit)
{
 /*================================================================
开启档案或者 URL。
语法: int fopen(string filename, string mode);'r' 开档方式为唯读,档案指标指到开始处。

位元组的方式读取档案。
语法:string fread(int fp, int length);

字串加入斜线。
语法: string addslashes(string str);
==================================================================*/
$image = addslashes(fread(fopen($fileinput,"r"), 1000000));

$SQL = "Insert Into binary1 (id,title,body) values ('$id','$title','$image')";

/*=================================
删除档案。
语法: int unlink(string filename);
=================================*/
unlink($fileinput);

$error=mysql_query($SQL);
}


?>

显示图片
<?
 $db=mysql_connect("localhost","root","123") or die("connect error");
 mysql_select_db("yujin");

$SQL="select * from binary1 where id='3'";
$Show = mysql_query($SQL);

$getPhoto = mysql_fetch_object($Show);

$Type = $getPhoto->type;
// and send the correct header to the browser
Header("Content-type: $Type");

// now send the image
$Body = $getPhoto->body;
echo $Body;

/*
清出输出缓冲区。
语法: void flush(void);
*/
flush();
?>
whxbb 2002-02-28
  • 打赏
  • 举报
回复
读blob

$sql = "select id ,name, binarydata from mypic where id=1";
$stmt = @OCIParse($conn, $sql);
@OCIExecute($stmt);
@OCIFetchInto($stmt, &$info, OCI_ASSOC);
echo "ID=>" . $info['ID'];
echo "<br>Name=>" . $info['NAME'];
echo "<br>Content=>" . $info['BINARYDATA']->load();
@OCIFreeStatement($stmt);
whxbb 2002-02-28
  • 打赏
  • 举报
回复
读blob

$sql = "select id ,name, binarydata from mypic where id=1";
$stmt = @OCIParse($conn, $sql);
@OCIExecute($stmt);
@OCIFetchInto($stmt, &$info, OCI_ASSOC);
echo "ID=>" . $info['ID'];
echo "<br>Name=>" . $info['NAME'];
echo "<br>Content=>" . $info['BINARYDATA']->load();
@OCIFreeStatement($stmt);
whxbb 2002-02-28
  • 打赏
  • 举报
回复
写blob

$sql = "insert into mypic(id, name,BINARYDATA) values(mypic_id.nextval, '$name', EMPTY_BLOB()) RETURNING BINARYDATA into :BINARYDATA";
$stmt = @OCIParse($conn, $sql);
/** 生成一个本地LOB对象的描述符 */
$lob = @OCINewDescriptor($conn, OCI_D_LOB);
@OCIBindByName($stmt, ':BINARYDATA', &$lob, -1, OCI_B_BLOB);
@OCIExecute($stmt);
/** 载入文件 */
$lob->savefile($bfile);
@OCIFreeDesc($lob);
@OCIFreeStatement($stmt);
darzui 2002-02-26
  • 打赏
  • 举报
回复
btw:这篇文章我自己还没看:)太困了,该睡觉了
darzui 2002-02-26
  • 打赏
  • 举报
回复
这有一篇,讲mysql中存储图象的,我估计oracle中也差不多


* Image Database Functions

by: J. Patrick Ryans jpatrick@hellyeah.com July 1998

The following are provided niether with copyright or warranty. I do not
believe that any of the code in this file is copyrighted by anyone else, but
if it is, please let me know.

I gathered these functions from a larger php3 project to manage a
large and dynamic web site by keeping all html, images, and other file
contained in a MySQL database. I couldn't find one single example that
explained how to insert binary images into a database and then extract them
and display it to the browser.

The two major functions needed to load and display images are shown below,
but I have left out many details such as how to connect to the database,
how to use html forms, etc. That information can be picked up from a number
of places. I.e. check out:

http://webdev.berber.co.il
for examples of how to connect to a database, and

http://liquid-sky.media.mit.edu/file_upload.html
for how to use forms to upload files

My database has a table for storing binary data such as images and other
types. The schema is as follows:

#
# Table structure for table 'binary'
#
CREATE TABLE binary (
id int(11) DEFAULT '0' NOT NULL auto_increment,
title varchar(200) DEFAULT '' NOT NULL,
auth_id varchar(16) DEFAULT '' NOT NULL,
description varchar(200),
category varchar(50) DEFAULT '' NOT NULL,
body longblob,
cr_date date,
datestamp timestamp(14),
type varchar(50) DEFAULT '' NOT NULL,
KEY category (category),
KEY title (title),
KEY auth_id (auth_id),
PRIMARY KEY (id)
);
*/


/* Loading binary files into the database

There isn't room here to show the html forms, how to connect to the
database and the code for uploading the file into the database, so I'm
going to have to be a little terse here. I'm going to assume that you
know how to use forms to upload files, and I'm going to assume that you
know how to connect to your database which has a table of structure
similar to the schema shown above.

This script is expecting to recieve the following variables from the form:

$title // the title of the file
$auth_id // the id name of the author - field is specific to my needs
$desc // a short description
$cat // category, for organization purposes.
$type // mime type - something like "image/gif"

Be forewarned, error checking is very minimal in this routine, you will
probably want to do some more sanity checking in a production environment.
In my forms, I query the database to present a select list of valid author
ids and mime types.
*/
<? // load.php3

include "admin_connect.ini"; // connect as a user with insert auth.
include "main_h.inc"; // an html header for the page
echo "<center>\n";


$date = date("Y-m-d");
//$title = htmlentities($title); // you may want to clean up the input
// with statements like this.

// Check to see if a file was included in the input="file" tag

if(chop($fileinput)!=""){

// $fileinput should point to a temp file on the server
// which contains the uploaded image. so we will prepare
// the file for upload with addslashes and form an sql
// statement to do the load into the database.

$image = addslashes(fread(fopen($fileinput,"r"), 1000000));
$SQL = "Insert Into $PhotoTable
(title,auth_id,description,category,body,cr_date,type) values ('$title',
'$auth_id', '$desc', '$cat', '$image','$date','$type')";

// now we can delete the temp file
unlink($fileinput);
}
else{
echo "no file entered on form";
exit;
}

$Result = mysql_db_query ( $DB, $SQL );

if($Result==0){
echo "unsuccessful add";
}
else{
echo "successful add";
}
include "main_f.inc";
?>

/* Displaying an image from the database.

This is a very simple way to display the image that was loaded in the above
script. In this case we will query the image by title, but it would be
a simple matter to add other queries.

You must have the mime type for the image stored in the record with the
image data. As per the schema above, the mime type is stored in the 'type'
field.

Be careful that any includes and initialization files do not send anything
to the browser. You want the Header("Content-type: $type"); to be the first
line served.

To use the following script to display an image, use an image tag similar
to the following:

<img src="image.php3?title=myimage.gif">

*/
<? // image.php3

// connect to database with select access
include "user_connect.ini";
$SQL = "select body,type from $PhotoTable where title='$title'";
$Show = mysql ( $hDB, $hSQL );
$Rows = mysql_num_rows($hShow);

if($Rows<1){
// no image matches this query
}
else{
// at least one image has this title
$getPhoto = mysql_fetch_object($Show);

// we need to determine the mime type
$Type = $getPhoto->type;

// and send the correct header to the browser
Header("Content-type: $Type");

// now send the image
$Body = $getPhoto->body;
echo $Body;
flush();
}
?>



qsnake 2002-02-25
  • 打赏
  • 举报
回复
blob类型字段,以前网上有一篇文章讲的,搜索一下吧
不过最好还是直接存放在磁盘上好,不要浪费数据库
《风越代码生成器 [FireCode Creator]》是一款采用.Net FrameWork2.0框架,基于多种数据库的程序代码生成软件,可快速建立数据信息的:添加、编辑、查看、列表、搜索页面。通过界面模板与代码模板管理功能,可自定义生成程序的界面风格与输出代码,将最大限度提高ASPX/ASP/PHP/JSP等各种程序的编写效率。 01、支持生成的ASPX/ASP/PHP/JSP等页面在本机自动发布、调试(需安装IIS或对应WEB服务器) 02、支持Microsoft SQL Server、Microsoft Access、Oracle、MySql、Excel、FoxPro、FoxBase、Text等数据库连接 03、支持从数据表、视图(Access为查询)中读取数据字段 04、支持通过数据表中的组合主键传递参数 05、支持CSS统一设置页面风格 06、支持多种控件输入方式: 文本框 文本域 UBB文本框(支持UBB文本输入) 密码框 隐藏域 日期选择 单选框 复选框 下拉框 多选列表 单选列表 批量上载 上载文件 上载到库 07、支持多种信息显示方式: 显示文字 链接文件 文本框 文本域 显示图片 背景声音 视频播放 显示flash 08、支持检测提交字符的最小、最大输入长度、是否空值/唯一值、文本类型:★ 不检测 非特殊字符 仅单词字符 仅单词字符空格 仅26个字母 仅中文字符 仅允许整数 仅允许小数 仅日期/时间 仅日期+时间 仅日期 仅时间 仅允许邮箱 仅允许网址 仅允许IP 仅身份证号 仅国内电话 仅国内手机 09、支持对用户输入内容进行服务器端与客户端JS双重验证,有效防止SQL注入 ★ 10、支持自动生成多组多级的级联下拉框功能,快速建立如:省、市、县/公司、部门、小组等形式下拉框 ★ 11、支持表单提交超过100KB的文本数据 ★ 12、支持多文件上载、修改、删除记录时同步删除文件 13、支持控件名加密,使输入控件的名称与字段名不同,防止他人从客户端HTML中猜解 ★ 14、支持列表、搜索页面对数据记录进行实时排序、修改、批量删除等功能 15、支持表头/单独表格搜索两种布局方式 16、提供多种灵活翻页方案,用户可设置每页记录条数、上/下页、前/后N页、输入数字跳转到指定页面等,提高海量数据翻页速度 17、提供丰富的建站常用VB、JS函数库 ★ 18、更多扩展功能: 添加、修改页面在保存信息前进行预览功能 添加、修改页面提交后自动跳转并刷新列表页 字段描述批量格式化,可从字段名、描述生成,加强英文字符处理 列表、搜索页面隔行颜色、点击变色设置 根据数据库字段允许空值状态自动设置输入检测代码 页面皮肤模板设置,根据网页模板快速生成页面 ★ 设置指定字段在编辑信息时为只读状态 字段需要二次输入(如输入两次密码,以验证其正确性) ★ 在列表中直接批量编辑字段值,便于管理员维护 列表、搜索文件自动读取链接数据表值的实际信息 发送邮件功能,设置字段为邮件对应信息,可发送附件 ★ (繁、简、英)单语言版本 ★ 多语言页面实时翻译功能(默认:繁、简、英,可增加其它语言) ★ 多语言编码支持(GB2312/UTF8) ★ 生成提交校验码图片 ★ 搜索、列表文件以详细列表页(留言板风格)显示 生成权限,限制用户对指定页面的添加、删除、编辑权 将查询结果导出为CSV、HTML、EXCEL文件 ★ 生成不同选择字段的SQL语句 生成数据库字典 ★ 模板代码生成器,可自定义模板、变量生成代码 ★ 19、提供建站常用辅助工具: 屏幕尺 剪切板,保存最近指定次数的历史记录 常用加解密、编解码(DES、MD5、SHA、BASE64) 批量提取文本,支持正则表达式,可将HTML等文件中指定内容存入数据库 批量查找替换,支持正则表达式 批量文件、文件夹改名,支持正则表达式 正则表达式测试器(可设置、保存常用正则表达式) 获取键盘的按键值 网页隐藏资源下载,可下载无法直接得到URL的SWF、图片、音乐等资源 获取汉字的拼音、五笔编码、笔画数、笔顺名、部首等信息,并可进行汉字繁/简体,GB/BIG转换 代码编排器,CSS排版、JS、ASP、HTML注释清理

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧