PHP is truncating MSSQL Blob data (4096b), even after setting INI values. Am I missing one?

Posted by Dutchie432 on Stack Overflow See other posts from Stack Overflow or by Dutchie432
Published on 2010-12-21T14:51:18Z Indexed on 2010/12/21 14:54 UTC
Read the original article Hit count: 124

Filed under:
|
|
|
|

I am writing a PHP script that goes through a table and extracts the varbinary(max) blob data from each record into an external file. The code is working perfectly, except when a file is over 4096b - the data is truncated at exactly 4096.

I've modified the values for mssql.textlimit, mssql.textsize, and odbc.defaultlrl without any success.

Am I missing something here?

<?php 
 ini_set("mssql.textlimit" , "2147483647");
 ini_set("mssql.textsize" , "2147483647");
 ini_set("odbc.defaultlrl", "0");

 include_once('common.php');
 $id=$_REQUEST['i'];
 $q = odbc_exec($connect, "Select id,filename,documentBin from Projectdocuments where id = $id"); 
 if (odbc_fetch_row($q)){

  echo "Trying $filename ... ";
  $fileName="projectPhotos/docs/".odbc_result($q,"filename");

  if (file_exists($fileName)){
   unlink($fileName);
  } 

     if($fh = fopen($fileName, "wb")) {
      $binData=odbc_result($q,"documentBin");
         fwrite($fh, $binData) ;
         fclose($fh);
         $size = filesize($fileName);
         echo ("$fileName<br />Done ($size)<br><br>");
     }else {
      echo ("$fileName Failed<br>");
     }
 } 
?>

OUTPUT

Trying ... projectPhotos/docs/file1.pdf Done (4096)

Trying ... projectPhotos/docs/file2.zip Done (4096)

Trying ... projectPhotos/docsv3.pdf Done (4096)

etc..

© Stack Overflow or respective owner

Related posts about php

Related posts about sql