gpt4 book ai didi

php - 如何使用 PHP 将任何图像转换为位图图像并存储在 MySQL 数据库中?

转载 作者:行者123 更新时间:2023-11-30 22:43:16 24 4
gpt4 key购买 nike

如何使用PHP将任意图像转换为位图图像并存储在MySQL数据库中?
我想将图像存储在数据库中。如何将任何图像转换为位图图像。

<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>

这是文件上传代码,但我想转换位图图像并上传到MySQL数据库。

最佳答案

$imgData = file_get_contents($filename);
$img_for_db=mysql_real_escape_string($imgData);

将$img_for_db存入数据库,通过以下方式获取

$sql = "SELECT image FROM table WHERE id=1";
$result = mysql_query("$sql");
header("Content-type: image/jpeg");
echo mysql_result($result, 0);

关于php - 如何使用 PHP 将任何图像转换为位图图像并存储在 MySQL 数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30475828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com