[英]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 ? 清除问题,我在后端使用php,我想获取url图像的内容,然后将其作为BLOB类型插入mysql中? 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 ? 我想要这样的事情而不使用Imagick类,怎么办?
"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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.