I'm trying to save an image in a sql server 2000 database.
The data type of the column is image
.
Ben şu hatayı alıyorum:
Error: Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Operand type clash: text is incompatible with image, SQL state 22005 in SQLExecDirect in C:\xampp\htdocs\test\upload.php on line 25 Error, query failed
İşte kod:
Image Upload:
<?php
include('config.php');
if(is_uploaded_file($_FILES['userfile']['tmp_name']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$size = filesize($tmpName);
set_magic_quotes_runtime(0);//to desactive the default escape spacials caracters made by PHP in the externes files
$img_binaire = base64_encode(fread(fopen(str_replace("'","''",$tmpName), "r"), $size));
$query = "INSERT INTO test_image (image_name, image_content, image_size) ".
"VALUES ('{$fileName}','{$img_binaire}', '{$size}')";
odbc_exec($conn, $query) or die('Error, query failed');
echo "<br>File $fileName uploaded<br>";
echo "<br>File Size: $fileSize <br>";
}
?>
Image Show:
<?php
include('config.php');
$sql = "select * from test_image where id =2";
$rsl = odbc_exec($conn, $sql);
$image_info = odbc_fetch_array($rsl);
//$count = sizeof($image_info['image_content']);
//header('Accept-Ranges: bytes');
//header('Content-Length: '.$image_info['image_size']);
//header("Content-length: 17397");
header('Content-Type: image/jpeg');
echo base64_decode($image_info['image_content']);
//echo bindec($image_info['image_content']);
?>
Ne ben farklı yapmak gerekiyor?