使用postgres和php将oid导出到文件
我想将存储在我的数据库(postgres)中的所有文件导出到我的服务器中的一个文件夹并重命名它们。 我所做的:使用postgres和php将oid导出到文件,php,postgresql,postgresql-9.5,Php,Postgresql,Postgresql 9.5,我想将存储在我的数据库(postgres)中的所有文件导出到我的服务器中的一个文件夹并重命名它们。 我所做的: // integer, oid, varchar $sql = pg_query($conn,"select id, image, extension from table"); while($sqlRow = pg_fetch_assoc($sql)){ $newimage= $sqlRow['id'].'.'.$sqlRow['extension']; $pat
// integer, oid, varchar
$sql = pg_query($conn,"select id, image, extension from table");
while($sqlRow = pg_fetch_assoc($sql)){
$newimage= $sqlRow['id'].'.'.$sqlRow['extension'];
$path = '../_tmp/download/' . $newimage;
pg_query($conn, "begin");
$oid = pg_lo_create($conn);
$handle = pg_lo_open($conn, $oid, "w");
pg_lo_write($handle, "large object data");
pg_lo_close($handle);
pg_lo_export($conn, $oid, $path);
pg_query($conn, "commit");
}
使用这段代码,我正在导出和重命名苍蝇,但当我尝试打开文件时,它会给我一个错误(无效文件),文件大小为1kb,每个文件至少应为400KB
这里有什么问题?有什么错误?@AlexR,当我试图打开文件时,它显示“无效文件”,这意味着导出错误,但如果我尝试在浏览器上使用“encode(lou_get(image),'base64')”读取文件,它会起作用。也许你读取文件时出错(你没有显示该代码)。我不想读取该文件,只需导出到服务器上的文件夹。我在上面写这篇文章只是为了说明存储在数据库中的文件是有效的和有效的。