Announcement

Collapse
No announcement yet.

Save BLOB/VarBinary data field into a file in the server.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Save BLOB/VarBinary data field into a file in the server.

    Hello everybody..

    I need to save the VarBinary data of a Field (MSSQL database) into a file in my local disk. How can i do that in SC 7.

    Thanks.

  • #2
    You cannot 'just save' a blob from the internet on your local hd. The only way you can try is to create a download. First you can create a blank application to provide the necessary headers for downloading the blob (if you know what kind of blob it is) or save it on your remote server on a temp directory and provide a download link to there.

    In both situations the user has to decide how to open/save the file....
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      Thanks for the Reply Albert, helpful as Always....
      But in this case I already have the file (It can a PDF, a PIC or any file type) in a Database Field (VarBinary), and i need to save it in a file then i need to send that file By eMail.
      For example, this is my Query :

      Select file_binary,file_name from myTable where ID=100;

      How can i save to disk file_binary ?

      OR I found this on the internet, But i need to have the connection object in SC 7 to the DB first (How can I do that ?) :

      /* Connect to the local server using Windows Authentication and
      specify the AdventureWorks database as the database in use. */
      $serverName = "(local)";
      $connectionInfo = array( "Database"=>"AdventureWorks");
      $conn = sqlsrv_connect( $serverName, $connectionInfo);
      if( $conn === false )
      {
      echo "Could not connect.\n";
      die( print_r( sqlsrv_errors(), true));
      }

      /* Set up the Transact-SQL query. */
      $tsql = "SELECT LargePhoto
      FROM Production.ProductPhoto
      WHERE ProductPhotoID = ?";

      /* Set the parameter values and put them in an array. */
      $productPhotoID = 70;
      $params = array( $productPhotoID);

      /* Execute the query. */
      $stmt = sqlsrv_query($conn, $tsql, $params);
      if( $stmt === false )
      {
      echo "Error in statement execution.</br>";
      die( print_r( sqlsrv_errors(), true));
      }

      /* Retrieve and display the data.
      The return data is retrieved as a binary stream. */
      if ( sqlsrv_fetch( $stmt ) )
      {
      $image = sqlsrv_get_field( $stmt, 0,
      SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
      header("Content-Type: image/jpg");
      fpassthru($image);
      }
      else
      {
      echo "Error in retrieving data.</br>";
      die(print_r( sqlsrv_errors(), true));
      }

      /* Free statement and connection resources. */
      sqlsrv_free_stmt( $stmt);
      sqlsrv_close( $conn);


      Best regards..

      Comment

      Working...
      X