清除问题,我使用php作为我的后端,我想获取url图像的内容然后将其作为BLOB类型插入mysql中?这该怎么做 ?
我试过这段代码:
<?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");
}
?>
我想要这样的东西而不使用Imagick类,怎么样?
答案 0 :(得分:3)
"INSERT INTO images (image) VALUES('".mysqli_real_escape_string($link, file_get_contents($filename))."')"
答案 1 :(得分:0)
使用file_put_contents
file_put_contents($imgBlob, file_get_contents($url));