Page 1 of 1

Storing binary files in a MySQL table

Posted: Thu Sep 04, 2003 6:59 am
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

Posted: Thu Sep 04, 2003 6:41 pm
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.