Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

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

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 (I used virtually the same code to go through some images) 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'); //Connection to DB takes place here.
 $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..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Instead of setting odbc.defaultlrl to 0, try setting it to an actual value instead:

ini_set("odbc.defaultlrl", "100K");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...