Jump to content


Load blob field to SQL Server

  • Please log in to reply
No replies to this topic

#1 jmolleur

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 18 July 2006 - 08:47 PM

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?


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users