I am workng with Postgresql database. Trying to insert image in bytea type column using following code but error occurs. Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0xff
<html>
<body>
<?php
$con=pg_connect("host=localhost port=5432 dbname=Test user=postgres password=admin123");
if(isset($_POST['upload'])){
$image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); //SQL Injection defence!
$image_name = addslashes($_FILES['image']['name']);
echo $image_name;
$sql = "INSERT INTO img (image_name,image) VALUES ('{$image_name}', '{$image}')";
pg_query($con,$sql);
if (!pg_query($sql)) { // Error handling
echo "Something went wrong! :(";
}
else
echo "image uploaded";
}
?>
<form action="im_new.php" method="POST" enctype="multipart/form-data">
<label>File: </label><input type="file" name="image" />
<input type="submit" value="save" name="upload">
</form>
</body>
</html>