you have to add slashes to the content of the file before you insert it into the database. Something like this is your best bet.
$inFile = fopen('filename.txt','r');
while($data = fread('filename.txt',(1024*1020))) {
$data = addslashes($data);
$sql = "INSERT INTO fileData (fileID,Data) VALUES ($fID,\"$data\")";
mysql_query($sql);
} //end while
This allows you to store files of any size in the database by using two tables. If you put everything in one table then no query can exceed 1meg. Here is how you want to layout your database
CREATE TABLE IF NOT EXISTS fileInfo (
fileID BIGINT NOT NULL auto_increment,
fileName VARCHAR(100) NOT NULL,
fileSize BIGINT NOT NULL,
fileType VARCHAR(255) NOT NULL,
description TEXT,
PRIMARY KEY (ID),
UNIQUE fileName (fileName)
);
CREATE TABLE IF NOT EXISTS fileData (
ID BIGINT NOT NULL auto_increment,
fileID BIGINT NOT NULL,
Data BLOB,
PRIMARY KEY (ID)
)
of course fileID is an external key between the two tables, and the auto_increment id field in the fileData table allows you to rebuild the file by using an order by on this field. Even if multiple files are being inserted simultaneously the query
SELECT * FROM fileData WHERE fileID=1 ORDER BY ID
will still return the file pieces in order.