Jump to content


This topic is now archived and is closed to further replies.


Load blob field to SQL Server

Recommended Posts

I can load a blob field to a MySQL database, but I get a size restriction.  I use the following code:

      $binFile = $uploadfile;
      $imgLocation = str_replace("\\","/", $binFile);

      $handle = fopen($binFile, "rb");
      $data=addslashes(fread($handle, filesize($binFile)));
      $strDescription = addslashes(nl2br($txtDescription));
      mysql_connect($database, $username, $password);
      @mysql_select_db($database) or die("Unable to select database");
      $query="Update contacts set Tif_file='$data', email='test2', fname='$basefilename' where first = 'Alexa'";
      if (mysql_query($query)) {
          echo "Successful write<br>";
      } else {
          echo "Failed write<br>";
          echo mysql_errno() . ": " . mysql_error() . "<br>";

For small files, it uploads perfectly.  For larger files, it fails.  I think I can change the parameter on MySQL to allow a bigger file to be uploaded to the blob field. 

So, I tried to upload the bigger files to SQL Server 2000 instead of MySQL.  I can't upload those files because it would fail each time it encountered an apostrophe.  I can't change the apostrophe to another character because it's a TIF file that I'm trying to upload.  I used the same file to upload to the SQL Server 2000 database as I used to upload to the MySQL.

Anyone have any success uploading big files to SQL Server using php?  I used to do it in VB - I loaded the tif into a stream and then put it in the file.  Anyone have any source code to do this?


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.