在PHP中通过ODBC从Access获取二进制文件仅返回前4 KB

在PHP中通过ODBC从Access获取二进制文件仅返回前4 KB

问题描述:

I am trying to use PHP (CodeIgniter) and ODBC to fetch files (image, pdf, doc) stored in an Access database and show them in a browser. Unfortunately it returns only the first 4kb of every file.

$this->load->database();
$query = $this->db->query("select  noe,file from Sanad_File
where id=$id");
$rowim=$query->result();
if($rowim[0]->noe=="pdf")
  header('Content-Type: application/pdf');
else if ($rowim[0]->noe=="jpg") 
  header('Content-Type: image/jpeg');
else if ($rowim[0]->noe=="tif") 
header('Content-Type: image/tiff');
else if ($rowim[0]->noe=="doc" || $rowim[0]->noe=="docx")   
header('Content-Type: application/msword');
echo $rowim[0]->file;

I suspect that it's an ODBC issue. Can anyone help me find the solution?

The default value for longreadlen is 4096 (ref: here). You will need to increase that value via odbc_longreadlen().