我想将数据库(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'];
$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。< / p>
这是怎么了?