简体   繁体   中英

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 ?

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

使用file_put_contents

file_put_contents($imgBlob, file_get_contents($url));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM