PHP BLOB thành hình ảnh

Thông qua blob_listado. php chúng tôi có được (trong ListView) danh sách tên tệp (BLOB) chúng tôi lưu trong cơ sở dữ liệu

  • Sử dụng blob_obtener, chúng tôi sao chép tệp BLOB từ cơ sở dữ liệu vào thư mục hiện tại, chúng tôi luôn gọi nó là tạm thời. png

  • Chúng ta có thể có được thời gian. png sử dụng địa chỉ web của nó
    https. //kio40. 000webhost. com/thời. png

  • PHP BLOB thành hình ảnh

    blob25i759×1301 106 KB

    blob_listado. php

    
    

    blob_obtener. php

    
    

    PHP BLOB thành hình ảnh

    blob26i729×803 40. 4KB

    PHP BLOB thành hình ảnh

    blob27i1110×341 71. 1KB

    3. - Chúng tôi chuyển đổi tệp thành văn bản bằng Base 64, tải tệp lên và lưu dưới dạng BLOB

    Đôi khi chúng tôi không thể tải tệp trực tiếp lên (dưới dạng tệp), trong trường hợp này, chúng tôi chuyển đổi tệp thành văn bản bằng tiện ích mở rộng Base64
    Chúng tôi tải lên chuỗi Base 64 bằng tệp blob_upload2. php và PostText

    p366Bi_mysqli_imagenes_blob. aia (16. 2KB)

    PHP BLOB thành hình ảnh

    blob23i695×838 60. 8KB

    PHP
    Chúng tôi kết nối với cơ sở dữ liệu. Chúng tôi nhận được văn bản bằng cách sử dụng $data = $_POST;
    Mã PHP giải mã Base 64 và chúng tôi lưu thông tin đó dưới dạng BLOB
    [Chúng tôi có thể đã lưu văn bản trực tiếp dưới dạng một chuỗi, nhưng trong ví dụ này, chúng tôi thích BLOB hơn]
    Ngoài ra ta còn lưu file vào thư mục hiện hành

    
    

    4. - Danh sách tên tệp đã lưu. Lấy tệp được lưu trong BLOB

    Với

    $ sql = "CHỌN hình ảnh, phần mở rộng TỪ dibujo WHERE nombre = '$nombre'";
    $ result = mysqli_query ($link, "$sql");
    $ row = mysqli_fetch_array($result);
    file_put_contents('tạm thời. png', $row["hình ảnh"]);

    chúng tôi trích xuất nội dung của BLOB và lưu nó vào một tệp trong thư mục hiện tại, tên của tệp đó sẽ là. thời gian. png

    Bản tóm tắt. trong hướng dẫn này, bạn sẽ học cách xử lý dữ liệu BLOB bằng PHP PDO. Chúng tôi sẽ chỉ cho bạn cách chèn, cập nhật và chọn dữ liệu BLOB trong cơ sở dữ liệu MySQL

    PHP BLOB thành hình ảnh
    PHP BLOB thành hình ảnh

    Đôi khi, vì lý do bảo mật, bạn có thể cần lưu trữ các đối tượng dữ liệu lớn, chẳng hạn như. g. , hình ảnh, tệp PDF và video trong cơ sở dữ liệu MySQL

    MySQL cung cấp loại BLOB có thể chứa một lượng lớn dữ liệu. BLOB là viết tắt của đối tượng dữ liệu lớn nhị phân. Giá trị tối đa của đối tượng BLOB được chỉ định bởi bộ nhớ khả dụng và kích thước gói giao tiếp. Bạn có thể thay đổi kích thước gói giao tiếp bằng cách sử dụng biến 

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)
    0 trong MySQL và 

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)
    1 trong phần cài đặt PHP

    Hãy xem cách PHP PDO xử lý loại BLOB trong MySQL

    Đầu tiên, chúng ta tạo một bảng mới tên là

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)
    2 trong cơ sở dữ liệu mẫu để thực hành

    Bảng

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)
    2 chứa ba cột

    • Cột id là khóa chính, cột tự động tăng
    • Cột mime lưu trữ loại mime của tệp
    • Cột dữ liệu có kiểu dữ liệu là BLOB được sử dụng để lưu trữ nội dung của tệp

    Câu lệnh CREATE TABLE sau đây tạo bảng

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)
    2

    ________số 8_______

    Thứ hai, chúng tôi định nghĩa một lớp có tên là

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)
    5 với đoạn mã sau

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)

    Trong phương thức

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)
    6, chúng tôi mở một kết nối cơ sở dữ liệu đến cơ sở dữ liệu MySQL và trong phương thức 

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)
    7, chúng tôi đóng kết nối

    Chèn dữ liệu BLOB vào cơ sở dữ liệu

    PHP PDO cung cấp một cách thuận tiện để làm việc với dữ liệu BLOB bằng cách sử dụng các luồng và chuẩn bị các câu lệnh. Để chèn nội dung của tệp vào cột BLOB, bạn thực hiện theo các bước sau

    • Đầu tiên, mở tệp để đọc ở chế độ nhị phân
    • Thứ hai, xây dựng câu lệnh INSERT
    • Thứ ba, liên kết phần xử lý tệp với câu lệnh đã chuẩn bị bằng cách sử dụng phương thức  

      /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

      Code language: PHP (php)
      8 và gọi phương thức 

      /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

      Code language: PHP (php)
      9 để thực hiện truy vấn

    Xem phương pháp 

    /** * insert blob into the files table * @param string $filePath * @param string $mime mimetype * @return bool */ public function insertBlob($filePath, $mime) { $blob = fopen($filePath, 'rb'); $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':mime', $mime); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); return $stmt->execute(); }

    Code language: PHP (php)
    0 sau đây

    /** * insert blob into the files table * @param string $filePath * @param string $mime mimetype * @return bool */ public function insertBlob($filePath, $mime) { $blob = fopen($filePath, 'rb'); $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':mime', $mime); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); return $stmt->execute(); }

    Code language: PHP (php)

    Lưu ý rằng 

    /** * insert blob into the files table * @param string $filePath * @param string $mime mimetype * @return bool */ public function insertBlob($filePath, $mime) { $blob = fopen($filePath, 'rb'); $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':mime', $mime); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); return $stmt->execute(); }

    Code language: PHP (php)
    1 hướng dẫn PDO ánh xạ dữ liệu dưới dạng luồng

    Cập nhật cột BLOB hiện có

    Để cập nhật cột BLOB, bạn sử dụng kỹ thuật tương tự như được mô tả trong việc chèn dữ liệu vào cột BLOB. Xem phương pháp 

    /** * insert blob into the files table * @param string $filePath * @param string $mime mimetype * @return bool */ public function insertBlob($filePath, $mime) { $blob = fopen($filePath, 'rb'); $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':mime', $mime); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); return $stmt->execute(); }

    Code language: PHP (php)
    2 sau đây

    /** * update the files table with the new blob from the file specified * by the filepath * @param int $id * @param string $filePath * @param string $mime * @return bool */ function updateBlob($id, $filePath, $mime) { $blob = fopen($filePath, 'rb'); $sql = "UPDATE files SET mime = :mime, data = :data WHERE id = :id;"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':mime', $mime); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); $stmt->bindParam(':id', $id); return $stmt->execute(); }

    Code language: PHP (php)

    Truy vấn dữ liệu từ cột BLOB

    Các bước sau mô tả cách chọn dữ liệu từ cột BLOB

    • Đầu tiên, xây dựng một câu lệnh SELECT
    • Thứ hai, liên kết tham số tương ứng bằng phương pháp 

      /** * insert blob into the files table * @param string $filePath * @param string $mime mimetype * @return bool */ public function insertBlob($filePath, $mime) { $blob = fopen($filePath, 'rb'); $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':mime', $mime); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); return $stmt->execute(); }

      Code language: PHP (php)
      3 của đối tượng

      /** * insert blob into the files table * @param string $filePath * @param string $mime mimetype * @return bool */ public function insertBlob($filePath, $mime) { $blob = fopen($filePath, 'rb'); $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':mime', $mime); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); return $stmt->execute(); }

      Code language: PHP (php)
      4
    • Thứ ba, thực hiện tuyên bố

    Xem phương pháp 

    /** * insert blob into the files table * @param string $filePath * @param string $mime mimetype * @return bool */ public function insertBlob($filePath, $mime) { $blob = fopen($filePath, 'rb'); $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':mime', $mime); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); return $stmt->execute(); }

    Code language: PHP (php)
    5 sau đây

    /** * select data from the the files * @param int $id * @return array contains mime type and BLOB data */ public function selectBlob($id) { $sql = "SELECT mime, data FROM files WHERE id = :id;"; $stmt = $this->pdo->prepare($sql); $stmt->execute(array(":id" => $id)); $stmt->bindColumn(1, $mime); $stmt->bindColumn(2, $data, PDO::PARAM_LOB); $stmt->fetch(PDO::FETCH_BOUND); return array("mime" => $mime, "data" => $data); }

    Code language: PHP (php)

    Các ví dụ PHP MySQL BLOB

    Trong các ví dụ sau, chúng ta sẽ sử dụng lớp

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)
    5 để lưu ảnh GIF và tệp PDF vào cột BLOB của bảng

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)
    2

    PHP MySQL BLOB với các tệp hình ảnh

    Đầu tiên, chúng tôi chèn dữ liệu nhị phân từ tệp

    /** * insert blob into the files table * @param string $filePath * @param string $mime mimetype * @return bool */ public function insertBlob($filePath, $mime) { $blob = fopen($filePath, 'rb'); $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':mime', $mime); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); return $stmt->execute(); }

    Code language: PHP (php)
    8 vào cột BLOB của bảng

    /** * PHP MySQL BLOB Demo */ class BlobDemo { const DB_HOST = 'localhost'; const DB_NAME = 'classicmodels'; const DB_USER = 'root'; const DB_PASSWORD = ''; /** * Open the database connection */ public function __construct() { // open database connection $conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME); try { $this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD); //for prior PHP 5.3.6 //$conn->exec("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } /** * close the database connection */ public function __destruct() { // close the database connection $this->pdo = null; } }

    Code language: PHP (php)
    2 như sau

    $blobObj = new BlobDemo(); // test insert gif image $blobObj->insertBlob('images/php-mysql-blob.gif',"image/gif");

    Code language: PHP (php)
    PHP BLOB thành hình ảnh
    PHP BLOB thành hình ảnh

    Sau đó, chúng ta có thể chọn dữ liệu BLOB và hiển thị dưới dạng ảnh GIF

    $a = $blobObj->selectBlob(1); header("Content-Type:" . $a['mime']); echo $a['data'];

    Code language: PHP (php)
    PHP BLOB thành hình ảnh
    PHP BLOB thành hình ảnh

    PHP MySQL BLOB với tệp PDF

    Đoạn mã sau chèn nội dung của  tệp PDF 

    /** * update the files table with the new blob from the file specified * by the filepath * @param int $id * @param string $filePath * @param string $mime * @return bool */ function updateBlob($id, $filePath, $mime) { $blob = fopen($filePath, 'rb'); $sql = "UPDATE files SET mime = :mime, data = :data WHERE id = :id;"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':mime', $mime); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); $stmt->bindParam(':id', $id); return $stmt->execute(); }

    Code language: PHP (php)
    0 vào cột BLOB

    $blobObj = new BlobDemo(); // test insert pdf $blobObj->insertBlob('pdf/php-mysql-blob.pdf',"application/pdf");

    Code language: PHP (php)
    PHP BLOB thành hình ảnh
    PHP BLOB thành hình ảnh

    Sau đó, chúng ta có thể chọn dữ liệu PDF và hiển thị nó trong trình duyệt web như sau.

    $a = $blobObj->selectBlob(2); header("Content-Type:" . $a['mime']); echo $a['data'];

    Code language: PHP (php)
    PHP BLOB thành hình ảnh
    PHP BLOB thành hình ảnh

    Để thay thế tệp PDF bằng tệp ảnh GIF, bạn sử dụng phương pháp 

    /** * insert blob into the files table * @param string $filePath * @param string $mime mimetype * @return bool */ public function insertBlob($filePath, $mime) { $blob = fopen($filePath, 'rb'); $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':mime', $mime); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); return $stmt->execute(); }

    Code language: PHP (php)
    2 như sau.

    $blobObj->updateBlob(2, 'images/php-mysql-blob.gif', "image/gif"); $a = $blobObj->selectBlob(2); header("Content-Type:" . $a['mime']); echo $a['data'];

    Code language: PHP (php)

    Bạn có thể tải xuống mã nguồn của hướng dẫn này qua liên kết sau

    Tải xuống mã nguồn PHP MySQL BLOB

    Trong hướng dẫn này, chúng tôi đã chỉ cho bạn cách quản lý dữ liệu MySQL BLOB, bao gồm chèn, cập nhật và truy vấn blob

    Làm cách nào để hiển thị hình ảnh BLOB trong PHP?

    Để hiển thị hình ảnh BLOB cho trình duyệt, hãy tạo tệp PHP và thực hiện các thao tác sau. .
    Nhận dữ liệu hình ảnh được lưu trữ với trường MySQL BLOB trong cơ sở dữ liệu
    Đặt loại nội dung là hình ảnh (image/jpg, image/gif,…) sử dụng PHP header()
    In dữ liệu blob hình ảnh trong PHP

    Làm cách nào để chuyển đổi BLOB thành tệp trong PHP?

    //FILE $query= mysqli_query($conn, "CHỌN tên, loại, kích thước, nội dung TỪ tập tin WHERE id='". intval($id) .

    BLOB trong PHP là gì?

    BLOB là một đối tượng lớn nhị phân có thể chứa một lượng dữ liệu thay đổi . Bốn loại BLOB là TINYBLOB , BLOB , MEDIUMBLOB và LONGBLOB.

    Làm cách nào để chèn hình ảnh BLOB trong MySQL?

    Chèn Hình ảnh và Tệp dưới dạng dữ liệu BLOB vào Bảng MySQL .
    Cài đặt MySQL Connector Python bằng Pip
    Thứ hai, Thiết lập kết nối cơ sở dữ liệu MySQL trong Python
    Tạo một chức năng có thể chuyển đổi hình ảnh và tệp thành dữ liệu nhị phân
    Sau đó, Xác định truy vấn Chèn để nhập dữ liệu nhị phân vào bảng cơ sở dữ liệu