By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

Insert text file in a text field

P: n/a
Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

2) How can I insert a microsoft word file into a BLOB field of a
table ?

Please, could you help me with a simple example ?

Thank you .

Fab

Oct 18 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Thu, 18 Oct 2007 18:36:59 +0200, <el********@yahoo.itwrote:
Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

2) How can I insert a microsoft word file into a BLOB field of a
table ?

Please, could you help me with a simple example ?

mysql_query("INSERT INTO tablename (fieldname) VALUES
('".mysql_real_escape_string(file_get_contents('/path/to/file'))."')");
--
Rik Wasmus
Oct 18 '07 #2

P: n/a
On Thu, 18 Oct 2007 19:29:54 +0200, Rik Wasmus
<lu************@hotmail.comwrote:
On Thu, 18 Oct 2007 18:36:59 +0200, <el********@yahoo.itwrote:
>Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

2) How can I insert a microsoft word file into a BLOB field of a
table ?

Please, could you help me with a simple example ?


mysql_query("INSERT INTO tablename (fieldname) VALUES
('".mysql_real_escape_string(file_get_contents('/path/to/file'))."')");
Hmmm,
or: mysql_query("INSERT INTO tablename (fieldname) VALUES
(LOAD_FILE('/path/to/file'))");

For this you'd have to make sure:
- the database is on the same host as the file
- you have the FILE privilege
- the file is readable
- the filesize is less than max_allowed_packet bytes

--
Rik Wasmus
Oct 18 '07 #3

P: n/a
On Oct 18, 6:36 pm, electri...@yahoo.it wrote:
Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

2) How can I insert a microsoft word file into a BLOB field of a
table ?

Please, could you help me with a simple example ?

Thank you .

Fab
I wrote a tutorial on uploading files into a mysql database.
You can read it here :http://wiki.greenquery.com/doku.php?
id=understanding_php_classes#creating_uploadhandle r

I hope it's for some help to you.

//Michael

Oct 18 '07 #4

P: n/a
On 18 Oct, 17:36, electri...@yahoo.it wrote:
Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

2) How can I insert a microsoft word file into a BLOB field of a
table ?

Please, could you help me with a simple example ?

Thank you .

Fab
Do not multi-post. Cross-post if you must but don't multi
post It wastes people's time. http://www.blakjak.demon.co.uk/mul_crss.htm.

You have had answers from people on 2 different groups. If you had
cross posted instead of multi-posting, everyone would have seen that
the question had been answered.

Oct 19 '07 #5

P: n/a
On 18 Ott, 19:33, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Thu, 18 Oct 2007 19:29:54 +0200, Rik Wasmus

<luiheidsgoe...@hotmail.comwrote:
On Thu, 18 Oct 2007 18:36:59 +0200, <electri...@yahoo.itwrote:
Hallo,
I have 2 questions:
with php and mysql :
1) How can I insert a text file into a TEXT field of a table ?
2) How can I insert a microsoft word file into a BLOB field of a
table ?
Please, could you help me with a simple example ?
mysql_query("INSERT INTO tablename (fieldname) VALUES
('".mysql_real_escape_string(file_get_contents('/path/to/file'))."')");

Hmmm,
or: mysql_query("INSERT INTO tablename (fieldname) VALUES
(LOAD_FILE('/path/to/file'))");

For this you'd have to make sure:
- the database is on the same host as the file
- you have the FILE privilege
- the file is readable
- the filesize is less than max_allowed_packet bytes

--
Rik Wasmus

Thank you very much .

Another question:
after I put a text file in a text field,
then, how can I read this field content and put it into
a php variable ?

Many thanks .

Fabrizio

Oct 19 '07 #6

P: n/a
el********@yahoo.it wrote:
On 18 Ott, 19:33, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
>On Thu, 18 Oct 2007 19:29:54 +0200, Rik Wasmus

<luiheidsgoe...@hotmail.comwrote:
>>On Thu, 18 Oct 2007 18:36:59 +0200, <electri...@yahoo.itwrote:
Hallo,
I have 2 questions:
with php and mysql :
1) How can I insert a text file into a TEXT field of a table ?
2) How can I insert a microsoft word file into a BLOB field of a
table ?
Please, could you help me with a simple example ?
mysql_query("INSERT INTO tablename (fieldname) VALUES
('".mysql_real_escape_string(file_get_contents ('/path/to/file'))."')");
Hmmm,
or: mysql_query("INSERT INTO tablename (fieldname) VALUES
(LOAD_FILE('/path/to/file'))");

For this you'd have to make sure:
- the database is on the same host as the file
- you have the FILE privilege
- the file is readable
- the filesize is less than max_allowed_packet bytes

--
Rik Wasmus


Thank you very much .

Another question:
after I put a text file in a text field,
then, how can I read this field content and put it into
a php variable ?

Many thanks .

Fabrizio

http://www.php.net/manual/en/ref.mysql.php

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 19 '07 #7

P: n/a
On Thu, 18 Oct 2007 09:36:59 -0700, electric_r wrote:
Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?
textarea value="<?php echo thefile; ?>" something like that
>
2) How can I insert a microsoft word file into a BLOB field of a table ?
wouldn't it be more practical to just store the file's path instead of the file itself?
>
Please, could you help me with a simple example ?

Thank you .

Fab
Oct 19 '07 #8

P: n/a
Henri wrote:
On Thu, 18 Oct 2007 09:36:59 -0700, electric_r wrote:
>Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

textarea value="<?php echo thefile; ?>" something like that
He's talking about a table in a SQL database.
>2) How can I insert a microsoft word file into a BLOB field of a table ?

wouldn't it be more practical to just store the file's path instead of the file itself?
Not necessarily. Often times I'll store files in a database. A lot of
good reasons to do so (which should be discussed in a SQL newsgroup).
>Please, could you help me with a simple example ?

Thank you .

Fab


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 19 '07 #9

P: n/a
Henri wrote:
On Thu, 18 Oct 2007 09:36:59 -0700, electric_r wrote:
>Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

textarea value="<?php echo thefile; ?>" something like that
>2) How can I insert a microsoft word file into a BLOB field of a table ?

wouldn't it be more practical to just store the file's path instead of the file itself?
Actually it isn't.I ended up with EVERYTHING - files and images - in the
database simply because backing up the database then backs up EVERYTHING.

But I wouldn't use a text area to input a file..use the FILE input command.
>Please, could you help me with a simple example ?

Thank you .

Fab
Oct 19 '07 #10

P: n/a
On Fri, 19 Oct 2007 23:26:07 +0100, The Natural Philosopher wrote:
Henri wrote:
>On Thu, 18 Oct 2007 09:36:59 -0700, electric_r wrote:
>>Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

textarea value="<?php echo thefile; ?>" something like that
>>2) How can I insert a microsoft word file into a BLOB field of a table
?

wouldn't it be more practical to just store the file's path instead of
the file itself?

Actually it isn't.I ended up with EVERYTHING - files and images - in the
database simply because backing up the database then backs up
EVERYTHING.
ok, good point. I was just not thinking in terms of back ups.
But I wouldn't use a text area to input a file..use the FILE input
command.
that was my misanderstanding the first question.
>
>>Please, could you help me with a simple example ?

Thank you .

Fab
Oct 20 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.