Home > Database > Mysql Tutorial > body text

How to Insert .pdf Files into MySQL BLOBs in PHP?

Linda Hamilton
Release: 2024-10-23 20:09:30
Original
566 people have browsed it

How to Insert .pdf Files into MySQL BLOBs in PHP?

Inserting .pdf Files into MySQL BLOBs Using PHP

Storing files directly in a database can be problematic, particularly for large files such as PDFs. Despite this, it is possible to store .pdf files in MySQL databases as BLOBs (Binary Large Objects) using PHP.

To insert a .pdf file into a BLOB column, you can use the following code snippet:

<code class="php">$sql = "INSERT INTO table (data) VALUES (?)";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("b", file_get_contents("path/to/file.pdf"));
$stmt->execute();</code>
Copy after login

However, it is important to note that storing BLOBs in MySQL is not recommended due to potential performance and maintenance issues. It is generally preferable to store the file on the filesystem and save only a reference (e.g., the file path) in the database. This approach reduces the database size and improves efficiency.

The above is the detailed content of How to Insert .pdf Files into MySQL BLOBs in PHP?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!