Storing binary files in a MySQL table

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

Storing binary files in a MySQL table

Post by bluenote »

Hi there,

I am working around with a medium-sized CMS based on MySQL and PHP. One of the backend modules needs a new feature - a possibility to upload & store binary files (Images, PDF's, Excel Sheets, Word Files, HTML Files, ...) in a DB table.

They should NOT be displayed on any website but be downloadable for a certain range of users.

I know about the basics

Code: Select all

<?php
echo "<FORM NAME="insert" ACTION="insert.php" METHOD="POST" onSubmit="return chkinsert()" onreset="return confirmReset(this)" ENCTYPE="multipart/form-data">\n";

?>

Code: Select all

<?php

echo "<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="31457280">\n";
echo "<INPUT TYPE=file NAME="p113" VALUE="" SIZE=40>\n";

?>
and I have a "longblob" field named "p113" in the destination table.

But every time I select a file and run the insert script, NOTHING is stored in my BLOB field :cry: - without any error_messages in the apache logs. The rest of the information to store is written to the DB as desired.

What am I doing wrong? Any ideas or suggestions are welcome. By the way: how can i fetch the addiotinal file informations like size etc. automatically and store them with the filke itself?

Greez, bluenote
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Dont know what you have in your code, but I'm using something like:

Code: Select all

$data = addslashes(fread(fopen($thefile, "r"), filesize($thefile)));
I'm thinking that perhaps you are missing addslashes or something (?).

About the filesize, this page might help you out more.
Post Reply