Zizoo Zizoo - 2 months ago 7
MySQL Question

How to get image from url and save it in mysql as BLOB ? php

Clear form the question ,I'm using php for my backend , I want to get content of url image then insert it in mysql as BLOB type ? how to do this ?

I tried this code :

<?php
$servername = "localhost";
$username = "root";
$password = "111";
$dbname = "111";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);


$data = file_get_contents("https://images-na.ssl-images-amazon.com/images/M/MV5BMTI3ODc2ODc0M15BMl5BanBnXkFtZTYwMjgzNjc3._V1_UX182_CR0,0,182,268_AL_.jpg");


$sql = "UPDATE employee SET realPhoto='".$data."' WHERE id= 2";

if ($conn->query($sql) === TRUE) {
echo ("true");

} else {

echo ("false");
}

?>


I want something like this without using Imagick class , how ?

Answer
"INSERT INTO images (image) VALUES('".mysqli_real_escape_string($link, file_get_contents($filename))."')"
Comments