Zizoo Zizoo - 1 year ago 108
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 :

$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 Source
"INSERT INTO images (image) VALUES('".mysqli_real_escape_string($link, file_get_contents($filename))."')"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download