MySQL / PHP file upload?

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
drgnjucr
Forum Commoner
Posts: 30
Joined: Thu Jan 27, 2005 3:06 pm
Location: NJ
Contact:

MySQL / PHP file upload?

Post by drgnjucr »

Hello,
I am looking for a way to sucessfully upload physical documents (to include MSWord,MSExcel,etc..) to a MySQL db.
I've read a bit, and executed some code to upload the file(s) however it dumps the content into a BLOB filed type in MySQL and the content is destroyed if it's not a plain text file.
What I'm trying to acomplish here is my own way of document management/sharing amoung different organizations in my company and allow a "one stop shop" for putting/retreiving all related documents to a specific project. Also with that, I'll store the las time the file was upload; by whom, etc.. as well as the last download time, etc...

Anyone know if this is possible?

Thank you very much!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you want to store the physical file in mysql, it needs to be in a BLOB type.. either BLOB, MEDIUMBLOB, or LONGBLOB as these are designed for binary data. BLOB has a maximum size of 64K, MEDIUMBLOB holds 16M, and LONGBLOB holds 4GB.. choose your poison :)
drgnjucr
Forum Commoner
Posts: 30
Joined: Thu Jan 27, 2005 3:06 pm
Location: NJ
Contact:

Post by drgnjucr »

Hi, Thanks.

Do you know how I would insert the actual file into the mediumblob filed? Currently, it looks like I'm opening the file with "fopen()" and it's attempting to place the content into the field.. at least I think that's what it's doing.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

file_get_contents() ... however, I would personally use a version control software :)
drgnjucr
Forum Commoner
Posts: 30
Joined: Thu Jan 27, 2005 3:06 pm
Location: NJ
Contact:

Post by drgnjucr »

I'm sorry to ask, but would you be able to help me with the syntax of the function?
drgnjucr
Forum Commoner
Posts: 30
Joined: Thu Jan 27, 2005 3:06 pm
Location: NJ
Contact:

Post by drgnjucr »

Well, sort of an example as to how I put the file into the db with that function.
drgnjucr
Forum Commoner
Posts: 30
Joined: Thu Jan 27, 2005 3:06 pm
Location: NJ
Contact:

Post by drgnjucr »

Actually, the code I have does work, just not in FF. It works fine in IE. hmmm.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Please use the edit button..
and post your code..
drgnjucr
Forum Commoner
Posts: 30
Joined: Thu Jan 27, 2005 3:06 pm
Location: NJ
Contact:

Post by drgnjucr »

Ok, so I've narrowed it down even more. It's just M$ files that are not working when downloaded from FF.
It seems like upload works in FF...not as good as in IE, but it seems to work.

I've tried text files, and zip files.. all work no problem with FF. Just excel, word seem to have issues.

The working code I used is here:
http://www.php-mysql-tutorial.com/php-mysql-upload.php

Anyone know how to fix this?
drgnjucr
Forum Commoner
Posts: 30
Joined: Thu Jan 27, 2005 3:06 pm
Location: NJ
Contact:

Post by drgnjucr »

Well, with more testing.......

When the file file is uploaded with FF (a word, excel) and you attempt to download it with IE... the "FileType" is blank.. but it opens anyhow.
If you upload it with FF, and try to dl it with FF and you choose to "Save to Disk" FF does not know what type of file it is. If you manually choose excel, it opens.
If you choose to open with when you try to DL with FF it will have the default application there, like.. excel. If you open it, it will open.

If it's all done with IE, works like champ. If you upload it with IE, and download it anyway with FF, works like a champ.

Seems like a slight bug with FF ....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it is not a bug in Firefox.. it's a problem of not knowing the proper content-type
Post Reply