Uploading .txt or .doc files to a database.

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
Darragh3277
Forum Newbie
Posts: 12
Joined: Tue Jun 24, 2008 9:19 am

Uploading .txt or .doc files to a database.

Post by Darragh3277 »

Hey all, I've another question to put to ye.

I'm making a website for my local sports team. Each week I will recive a match report as a .txt or .doc file. I would like to use a form to upload this data and then be able to display the contents of the file on a page. How do I do this? Is there a way to extract the text from the file or can I just upload the file?

I know I could just use a textarea but I would really like to be able to submit a .doc file and have it displayed.
madan koshti
Forum Commoner
Posts: 50
Joined: Fri Jun 06, 2008 4:25 am

Re: Uploading .txt or .doc files to a database.

Post by madan koshti »

I think your .txt should be csv ??

And there will be one php script for upload and importing the csv file to the database so that you can use data from database to display on the web page.

csv will be like this :

columnname1;columnname2
value1;value2
Darragh3277
Forum Newbie
Posts: 12
Joined: Tue Jun 24, 2008 9:19 am

Re: Uploading .txt or .doc files to a database.

Post by Darragh3277 »

I'm not sure if that would work the way I want it? Could you explain how you would use it this case? Sorry i'm pretty new to php/mysql

What im essentially looking for is something like a blog. I write a story, then I upload it.
madan koshti
Forum Commoner
Posts: 50
Joined: Fri Jun 06, 2008 4:25 am

Re: Uploading .txt or .doc files to a database.

Post by madan koshti »

Do you need a php script for importing .csv file into table ?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Uploading .txt or .doc files to a database.

Post by jayshields »

No, he doesn't. He wants a means of uploading a .doc or .txt file and publishing them on the internet.

The .doc format is Microsoft, so it's not open. I think there are libraries out there to work with that format, but .txt would be a hell of alot easier.

You can either extract the text from the file and put it in a database, or just upload the file to your server and store the filename in the database, or, even easier, just upload the file to your server and not use a database at all (maybe create a listings page which links to every .txt file in your upload directory).

You could start by looking at

Code: Select all

fopen()
and/or

Code: Select all

move_uploaded_file()
lyleyboy
Forum Commoner
Posts: 27
Joined: Sat Mar 18, 2006 5:05 am
Location: Birmingham, UK

Re: Uploading .txt or .doc files to a database.

Post by lyleyboy »

Might not be the most help but you could just use the file read to open the file read the contents, dump into a table then delete the file.

It would mean that everything in the file would be copied so make sure to look for dodgy characters etc.

Hope it helps
Darragh3277
Forum Newbie
Posts: 12
Joined: Tue Jun 24, 2008 9:19 am

Re: Uploading .txt or .doc files to a database.

Post by Darragh3277 »

Wow thanks for all the great replies! Just what I needed!

Thanks everyone and thanks jayshields I was looking for just that!
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Uploading .txt or .doc files to a database.

Post by Ollie Saunders »

Yeah store the files in the file system not in the database, much easier.
Post Reply