将图像路径转换为适合存储在MySQL Blob中的数据

时间:2021-01-24 16:59:02

I have a file in the location

我在该位置有一个文件

$imgloc = "../images/bg.jpg";

How do I:

我如何能:

  1. Load the image into a PHP variable
  2. 将图像加载到PHP变量中

  3. Turn into a BLOB suitable data type (if not already)
  4. 变成BLOB合适的数据类型(如果还没有)

  5. Insert into MySQL (If any additional steps are needed)
  6. 插入MySQL(如果需要任何其他步骤)

1 个解决方案

#1


$imgHandler = fopen (imgloc, 'rb'); // open with read binary
$imgContent = fread ($imgHandler , filesize ($imgloc));
// now you can store $imgContent in MySQL

#1


$imgHandler = fopen (imgloc, 'rb'); // open with read binary
$imgContent = fread ($imgHandler , filesize ($imgloc));
// now you can store $imgContent in MySQL