0

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>
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.