|
发表于 2003-12-11 01:36:50
|
显示全部楼层
你的脚本过程都正确了.语法问题自己找吧.PHP语法快忘完了.
我找到了原来写的一个上传到mysql数据库的一个脚本.可以实现文件的上传入库和读取输出(Under GNU/Linux).方法参考一下,具体到实际再根据你的情况自己改啦.
[code:1]
create table if not exists image(
id bigint(20) not null,
data blob not null,
filesize bigint not null,
filetype char(10),
memo varchar(255),
primary key (id)
);
[/code:1]
节选一部分PHP,原文件比较长
[code:1]
............
<form enctype="multipart/form-data" action="xxxxx.php" method="post">
............
<tr>
<td>
<div align="right">图象文件</div>
</td>
<td>
<input type="hidden" name="MAX_FILE_SIZE" value="3000000">
<input type="file" name="userfile">
</td>
</tr>
.............
[/code:1]
下面是入库文件节选
[code:1]
.............
if (!(empty($_FILES['userfile']['tmp_name']))) {
$filename=$_FILES['userfile']['name'];
$path_parts=pathinfo($filename);
$filetype=$path_parts['extension'];
$filename=$_FILES['userfile']['tmp_name'];
$data=addslashes(fread(fopen("$filename", "r"), filesize($filename)));
$sqlquery="insert into image (id,data,filesize,filetype) values (".$id.",'$data',".filesize($filename).",'".$filetype."')";
$queryresult=mysql_query($sqlquery)
or die("Invalid query: ".mysql_error());
}
.............
[/code:1]
最后是取出了
[code:1]
.............
$sqlquery1="select data,filetype from image where id=".$row['id'];
$queryresult1=mysql_query($sqlquery1)
or die("Invalid query: ".mysql_error());
if ($row1=mysql_fetch_array($queryresult1)) {
$filetype=$row1['filetype'];
$data=$row1['data'];
$filename=$imagepath."temp_".$i++.".".$filetype;
if (!$handle=fopen($filename,'wb')) {
die("Could not open $filename");
}
if (!fwrite($handle,$data)) {
die("Could not write $filename");
}
fclose($handle);
echo "<td><img src=images/".basename($filename)."></td>";
} else {
echo "<td>No image</td>";
}
.............
[/code:1] |
|