我的附件下载后不能查看,文件大小真实 请高手帮忙把脉!

flowingtree 2006-02-21 09:02:20
我的附件下载后不能查看,文件大小真实

请高手帮忙把脉!

数据库:pgsql
涉及的表:

create table $module.attach(id serial primary key,name char(200),attachment bytea,type char(200),size integer) with oids





文件上传过程:

<?php
function bytea_encode($file)
{
$attach_buf = @file_get_contents($file);
return pg_escape_bytea($attach_buf);
}
$name = $_FILES[sheetattachment][name];
$attachment = bytea_encode($_FILES[sheetattachment][tmp_name]);
$type = $_FILES[sheetattachment][type];
$size = $_FILES[sheetattachment][size];
$sql = "insert into attach (name,attachment,type,size)
values ('$name','$attachment'::bytea,'$type',$size)";
$db->query($sql);
?>




<?php
require_once ('global.php');
$id = intval($_GET[id]);
$sql = "select * from attach where id=$id";
$row = $db->getRow($sql);

$attachment = pg_unescape_bytea($row[attachment]);

header('Content-Type: '.$row[type]); //文件类型
header("Content-Length: ".$row[size]); //文件长度
header('Content-Disposition: attachment; filename='.$row[name]); //提示下载
echo $attachment;
exit;
?>
...全文
107 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
flowingtree 2006-02-23
  • 打赏
  • 举报
回复
问题已经解决

我的<?php?>前面有一个空格


呵呵,顺便提醒大家小心严谨哦
flowingtree 2006-02-22
  • 打赏
  • 举报
回复
晕啊. char(200)只是名字呀

attachment bytea 这才是文件内容呀.......................
gu1dai 2006-02-22
  • 打赏
  • 举报
回复
char(200)
似乎是你的字段太小了。建议查下pgsql的字段类型,找到二进制存储类型。
flowingtree 2006-02-22
  • 打赏
  • 举报
回复
..............waiting...................................


高手

21,886

社区成员

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

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