|
|
|
SQL Server อ่าน Binaray Data ด้วย PHP อยาก select ข้อมูล แบบ image ออกมาเป็น binary แบบ 0x0000 ทำไงครับ ช่วยที |
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
if($_FILES["filUpload"]["name"] != "")
{
//*** Insert Record ***//
$objConnect = mssql_connect("localhost","sa","") or die("Error Connect to Database");
$objDB = mssql_select_db("mydatabase");
$strSQL = "INSERT INTO files ";
$strSQL .=" ( Name, FilesType,FilesName) ";
$strSQL .=" SELECT '".$_POST["txtName"]."','".$_FILES["filUpload"]["type"]."', ";
$strSQL .=" BulkColumn FROM OPENROWSET( ";
$strSQL .=" Bulk '".$_FILES["filUpload"]["tmp_name"]."', SINGLE_BLOB) AS BLOB ";
$objQuery = mssql_query($strSQL);
echo "Copy/Upload Complete<br>";
mssql_close($objConnect);
}
?>
<a href="PageUploadToSQLServer3.php">View files</a>
</body>
</html>
Code (PHP)
<?
$objConnect = mssql_connect("localhost","sa","") or die("Error Connect to Database");
$objDB = mssql_select_db("mydatabase");
$strSQL = "SELECT * FROM files WHERE FilesID = '".$_GET["FilesID"]."' ";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mssql_fetch_assoc($objQuery);
header("Content-Type: ".$objResult["FilesType"]);
echo $objResult["FilesName"];
?>
Go to : PHP Upload File BLOB/Image to SQL Server Database (mssql-OPENROWSET)
|
|
|
|
|
Date :
2011-06-02 18:14:21 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|