473,416 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

File.txt

Hi at all,
how can I do to insert into a HTML page a file .txt stored in the same
directory of the server where is the html file that must display the text
file.txt?
Thank you very much
P.Pietro
Jul 23 '05 #1
12 2543
"A.M." <NO****@eurotime.it> skrev i meddelandet
news:VJ*********************@twister2.libero.it...
Hi at all,
how can I do to insert into a HTML page a file .txt stored in the same
directory of the server where is the html file that must display the text
file.txt?
Thank you very much
P.Pietro


You can't with javascript.

With server-side PHP it's as easy as: echo file_get_contents('file.txt');

Joakim Braun
Jul 23 '05 #2
Joakim Braun wrote:
"A.M." <NO****@eurotime.it> skrev i meddelandet
news:VJ*********************@twister2.libero.it...
Hi at all,
how can I do to insert into a HTML page a file .txt stored in the same
directory of the server where is the html file that must display the text
file.txt?
Thank you very much
P.Pietro


You can't with javascript.

With server-side PHP it's as easy as: echo file_get_contents('file.txt');

Joakim Braun


It's even easier with HTML:

<iframe src="file.txt"></iframe>

(assuming browser support for <iframe>)

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #3
In article <VJ*********************@twister2.libero.it>, A.M.
<NO****@eurotime.it> wrote:
Hi at all,
how can I do to insert into a HTML page a file .txt stored in the same
directory of the server where is the html file that must display the text
file.txt?
Thank you very much
P.Pietro

Search for information on iFrame. It is not javascript but an HTML
solution. It is basically a frame that can be inserted anywhere in a
page. I know that it will display HTML and I'm pretty sure that it will
also display a text file but I may be wrong.

--
Dennis Marks
http://www.dcs-chico.com/~denmarks/
Mail to the return email address is bounced.
Go to web site for active email address.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #4
Dennis M. Marks wrote:
[...] A.M. [...] wrote:
how can I do to insert into a HTML page a file .txt stored in the
same directory of the server where is the html file that must
display the text file.txt?


Search for information on iFrame. It is not javascript but an HTML
solution. It is basically a frame that can be inserted anywhere in a
page. I know that it will display HTML and I'm pretty sure that it
will also display a text file but I may be wrong.


The "iframe" element embeds da resource, not only HTML documents.
Thus it should work with any resource. If it does not, the UA is
borken.

Note that this element is not supported by Netscape 4. And it has
recently been recommended to use the "object" element instead since
it is more flexible. However, the support for the latter element
is still not properly implemented in some browsers, so a combination
of both may be a viable solution:

<object data="foo.txt" type="text/plain">
<iframe src="foo.txt">
<a href="foo.txt">foo.txt</a>
</iframe>
</object>
PointedEars
--
$n="\e[0;40;32m";for(1..10){print"\ec$n\n".$"x(15)."\e[1;35mY$n".$"x15;for(1..8){print$/.$"x($a=16-$_);$c=int
rand($d=2*$_);for(2..$d){$f=31+int
rand(3);print($_-$c?"X":"\e[$f;1m*$n")}print$"x$a}print
$/.$"x(31)."\e[0m\n".$"."Merry Christmas".$/x2;select$q,$q,$q,0.5} # ;)
Jul 23 '05 #5
Hello,
Note that this element is not supported by Netscape 4. And it has
recently been recommended to use the "object" element instead since
it is more flexible. However, the support for the latter element
is still not properly implemented in some browsers, so a combination
of both may be a viable solution:

<object data="foo.txt" type="text/plain">
<iframe src="foo.txt">
<a href="foo.txt">foo.txt</a>
</iframe>
</object>

But how can access the content of the foo.txt file via javascript? Let
assume that the foo.txt is not the well formed HTML document?
Is it possible to access the file content?

regards
maciek
Jul 23 '05 #6
Zenon wrote:
But how can access the content of the foo.txt file via javascript?
Let assume that the foo.txt is not the well formed HTML document?
Is it possible to access the file content?


Unless the UA provides a DOM for text/plain documents, this
is impossible, and I know of no UA that provides such a DOM.
PointedEars
Jul 23 '05 #7
Thomas 'PointedEars' Lahn wrote:
Zenon wrote:
But how can access the content of the foo.txt file via javascript?
Let assume that the foo.txt is not the well formed HTML document?
Is it possible to access the file content?


Unless the UA provides a DOM for text/plain documents, this
is impossible, and I know of no UA that provides such a DOM.


I take that back. The Gecko DOM provides its HTML DOM for text/plain
documents, that is, the content of the text file can be accessed with

iframeReference.document.body.innerHTML

and in newer release versions

iframeReference.document.body.textContent

at least in my Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8a3)
Gecko/20040717 Firefox/0.9.1+.
PointedEars
Jul 23 '05 #8
Oh Pointed Eared One,
Zenon wrote:
But how can access the content of the foo.txt file via javascript?
Let assume that the foo.txt is not the well formed HTML document?
Is it possible to access the file content?


Unless the UA provides a DOM for text/plain documents, this
is impossible, and I know of no UA that provides such a DOM.


Check out the XML HTTPRequest Object, supported by both Mozilla,
(somewhat in) Safari and Internet Explorer with ActiveX enabled
(don't know about the others). There is also an interface of the
Document Object that allows XML files to be parsed. Check out
http://jibbering.com/2002/4/httprequest.html

-- Jimmy
Jul 23 '05 #9
Jimmy Cerra wrote:
Oh Pointed Eared One,
Zenon wrote:
But how can access the content of the foo.txt file via javascript?
Let assume that the foo.txt is not the well formed HTML document?
Is it possible to access the file content?
Unless the UA provides a DOM for text/plain documents, this
is impossible, and I know of no UA that provides such a DOM.


Check out the XML HTTPRequest Object, [...]


I know about XMLHttpRequest. It is only supported by newer UAs (that
you mentioned) and by older ones (IE on 32 bit Windows, AFAIK not on
the Mac) using support for additional APIs (ActiveX) that is probably
disabled due to security issues. And this is not access to a DOM, so
not necessarily the desired access to the content of a text file which
may include access to certain sections and paragraphs.
There is also an interface of the Document Object that allows XML
files to be parsed.


Yes, *XML* documents, not text/plain documents. It may work with
those, but it does not need to.
PointedEars
Jul 23 '05 #10
Dear One with Pointed Ears,
I know about XMLHttpRequest. It is only supported by newer UAs (that
you mentioned)
Which, depending on the domain may make sense or not. Whenever I
develop web applications, I use usually assume that a web surfer will
browse with a UA released at least four years ago on Windows, and
three on other machines. This covers 99% of my audience.Not an
unreasonable assumption, if you are going to use JavaScript. That
includes all browsers that support the XMLHttpRequest object. If the
user is browsing with something older, then they are already
comfortable surfing with a good portion of web sites not rendering as
intended. Most web sites assume a browser at least that old nowadays.

the Mac) using support for additional APIs (ActiveX) that is probably
disabled due to security issues.
Any person browsing with ActiveX completely disabled is:

1. Computer literate; normal users don't know what ActiveX means.
2. Paranoid about ActiveX security holes.

The second fact is due to the number of different levels of ActiveX
support in Internet Explorer. If "Download signed ActiveX controls"
is disabled, then the threat is eliminated while allowing built-in
behaviors to still work. Completely disabling the technology isn't
necessary at all!

And this is not access to a DOM, so
not necessarily the desired access to the content of a text file which
may include access to certain sections and paragraphs.


The content is downloaded: I've used the interface and implementations
make it trivial to return the file as a string. Use Regular
Expressions to parse the sections, paragraphs, and other contents;
what other way can it be done?

There is also an interface of the Document Object that allows XML
files to be parsed.


Yes, *XML* documents, not text/plain documents. It may work with
those, but it does not need to.


I may have not been clear. I was referring to the interface of
XMLDocument, which has a load() method that dowloads and parses an xml
file. Thishas nothing to do with the XMLHttpRequest.

Besides, it is nice to have, just in case you want to deal with xml
files.

--
Jimmy Cerra
Jul 23 '05 #11
Jimmy Cerra wrote:
Dear One with Pointed Ears,
I know about XMLHttpRequest. It is only supported by newer UAs (that
you mentioned)
Which, depending on the domain may make sense or not.


It is a matter of the UA and its DOM, not of the domain. Excluding
users just because their software is not the right one is not a
successful approach in the mid-term for any Web site.
Whenever I develop web applications, I use usually assume that a web
surfer will browse with a UA released at least four years ago on Windows,
and three on other machines. This covers 99% of my audience.
[...]
What nonsense you have written here you maybe find out reading
<http://pointedears.de/scripts/test/whatami> and googling for
previous related discussions in this newsgroup (I think
"statistics" will do as keyword).
the Mac) using support for additional APIs (ActiveX) that is probably
disabled due to security issues.


Any person browsing with ActiveX completely disabled is:

1. Computer literate; normal users don't know what ActiveX means.


People *are* informed about the risks of their software, including ActiveX,
in the media (often incompletely, but that's not the point), including in
television, I have seen it even in the daily news feature (when again a
security hole was used to spread a worm). Whether they really pay attention
and draw the correct conclusions for the system they are using is a
psychological and different matter.
2. Paranoid about ActiveX security holes.
There is no paranoia required, only common sense. IE and ActiveX have been
and still are built-in security holes in (Windows) systems by themselves:
Allowing software to be downloaded and *executed* outside of a sandbox,
especially to operate then uncontrolled on the local file system, only
relying to the user's decision about what software is good and what is bad,
is a misguided approach just because the average user (and sometimes not
even experts) cannot estimate the full impact such piece of software can
have on the system (in that instant), especially on one with a loose user
account and security management (like Win9x and WinME; even Win2k and XP
running only with Administrator because some apps won't work without that
[reconfiguring file access restrictions, possibly requiring Registry
tampering, takes much time that people are seldom willing to invest,
they simply want things to work]).

The so-called "signed controls" feature has proven unreliable and security
restriction settings can be circumvented (and have been circumented in the
not-too-far past), you may want to read Bugtraq. Which is one of the
reasons why M$ supports and pursues TCPA (again the wrong approach; they
should instead revise their interfaces).

Almost daily "security updates" for often well- and long-known bugs at
windowsupdate.com speak chapters about the bad quality of the underlying
software, not of the expertise of those who find the security holes as
the marketing wants you to believe.
And this is not access to a DOM, so not necessarily the desired
access to the content of a text file which may include access
to certain sections and paragraphs.


The content is downloaded: I've used the interface and implementations
make it trivial to return the file as a string. Use Regular
Expressions to parse the sections, paragraphs, and other contents;
what other way can it be done?


Using RegExp to parse such a text reliably can be a pain-in-the-ass,
long strings do not help if there is not enough memory available on
the client, and it does not help if the interface interprets STAGO
and ETAGO as XML markup instead of plain text. If you would have
done either one (on unknown data) before, you would not have argued
this way.

The other way you are asking about is to provide for a DOM for text/plain
documents which would include interfaces for "sections, paragraphs, and
other contents" to be implemented as ECMAScript compatible prototypes,
for example. But since text/plain is not an interoperable format
(consider different newline sequences among platforms, different
encodings, e.g.), I doubt such a DOM will be ever widely implemented.
There is also an interface of the Document Object that allows XML
files to be parsed.


Yes, *XML* documents, not text/plain documents. It may work with
those, but it does not need to.


I may have not been clear. I was referring to the interface of
XMLDocument, which has a load() method that dowloads and parses an xml
file.


What part of my above statement is still unclear to *you*?
Thishas nothing to do with the XMLHttpRequest.
I know.
Besides, it is nice to have, just in case you want to deal with xml
files.


That is your only valid point. But serving plain text als text/xml
(which AFAIK would be required for the mentioned XML parser) is
neither what the OP was looking for nor would it always work.
PointedEars
Jul 23 '05 #12
Thomas 'PointedEars' Lahn,

I shouldn't have responded, since I'm going very off-topic. Perhaps
this would be better discussed via email. j i m b o l i s t at c o l
d m a i l, with "hot" replacing "cold" and the appropiate TLD concated
to the end, is a good public address to reach me.

Which, depending on the domain may make sense or not.
It is a matter of the UA and its DOM, not of the domain. Excluding
users just because their software is not the right one is not a
successful approach in the mid-term for any Web site.


What about ESPN.com, which excludes Netscape 4 and earlier? It is
still very sucessful. What about email services like Hotmail or
Yahoo! mail, which use JavaScript to perform various operations.
Doesn't that exclude browsers that only support the Dom level 0 common
interface? What about Trekweb.com, which requires a version 5 browser
and gets lots of traffic with few problems? There are hundreds of
sites that don't view as intended in older browsers.

It is unrealistic to support everything, otherwise everything would
still look like sites designed around 1995! Supporting the majority,
while allowing passible presentation for those still on older
browsers, is the best policy. Of course, there are exceptions to any
rule, but many sites (dare I say, most web site) don't need the amount
of backwards compatibility you are advocating. I reiterate, that the
best choice depends on the problem domain, just like any engineered
design!

Whenever I develop web applications, I use usually assume that a web
surfer will browse with a UA released at least four years ago on Windows,
and three on other machines. This covers 99% of my audience.
[...]


What nonsense you have written here you maybe find out reading
<http://pointedears.de/scripts/test/whatami> and googling for
previous related discussions in this newsgroup (I think
"statistics" will do as keyword).


Whenever I design a web site, I need to know what my users' browsers
can support. Pulling an image based on JavaScript DOM capibilities
gives you a rough estimate. 100% accuracy isn't a requirement: You
only need a rough estimate and feedback from users during a test
phase.

The capibilities that I use are generally only supported by browsers
released four-five years ago. So that's what I test with.

Any person browsing with ActiveX completely disabled is:

1. Computer literate; normal users don't know what ActiveX means.


People *are* informed about the risks of their software, including ActiveX,
in the media (often incompletely, but that's not the point), including in
television, I have seen it even in the daily news feature (when again a
security hole was used to spread a worm). Whether they really pay attention
and draw the correct conclusions for the system they are using is a
psychological and different matter.


That's a paradox. They can't be informed if they didn't pat attention
and draw the "correct conclusions." I get a different picture from
talking with people; they generally don't understand what a browser is
- ActiveX, HTML and other technologies are alien terms to them.

2. Paranoid about ActiveX security holes.


There is no paranoia required, only common sense. IE and ActiveX have been
and still are built-in security holes in (Windows) systems by themselves:
Allowing software to be downloaded and *executed* outside of a sandbox,


There are basically two types of ActiveX when talking about Internet
Explorer: the _built-in_ controls (such as dhtml behaviors) and the
_downloadable_ controls. The built-in controls generally don't have
significent security holes (to my knowledge). If you disable ability
to download ActiveX controls, how can a trogen be downloaded in the
first place? You can even disable running all ActiveX except for
Administrator approved controls, if you feel there is a bug disabling
ActiveX downloads. It simply isn't necessary to completely disable
the feature to prevent those kind of attacks.

Finally, the average user who thinks _all_ ActiveX is a security risk
will be running a browser that doesn't support it (like Opera or
Firefox).

especially to operate then uncontrolled on the local file system, only
relying to the user's decision about what software is good and what is bad,
is a misguided approach just because the average user (and sometimes not
even experts) cannot estimate the full impact such piece of software can
have on the system (in that instant), especially on one with a loose user
account and security management (like Win9x and WinME; even Win2k and XP
running only with Administrator because some apps won't work without that
[reconfiguring file access restrictions, possibly requiring Registry
tampering, takes much time that people are seldom willing to invest,
they simply want things to work]).
That run-on sentence is a little confusing. Please excuse anything
that I misunderstood.

A person lax on security wouldn't touch ActiveX settings in the first
place. Why wouldn't a security conscious individual create a special
account without net access specifically for those legacy applications
which require Administratior access?

The so-called "signed controls" feature has proven unreliable and security
restriction settings can be circumvented (and have been circumented in the
not-too-far past), you may want to read Bugtraq.
I'm not talking about signed controls. I'm talking about controls
built-into Internet Explorer. Downloadable signed controls can be
disabled without affecting the built-in controls.

Almost daily "security updates" for often well- and long-known bugs at
windowsupdate.com speak chapters about the bad quality of the underlying
software, not of the expertise of those who find the security holes as
the marketing wants you to believe.
I never said I trust Microsoft software. I think that I understand
how it works and how to secure it.

Using RegExp to parse such a text reliably can be a pain-in-the-ass,
Sometimes. It depends on the length, the complexity, and the problem
domain. Well structured text is easy to parse. And it can be parsed
on the fly with events too.

The other way you are asking about is to provide for a DOM for text/plain
No. I was referring to a DOM implementation for a different problem
domain, namely loading XML documents. It was a note.

There is also an interface of the Document Object that allows XML
files to be parsed.

Yes, *XML* documents, not text/plain documents. It may work with
those, but it does not need to.
I may have not been clear. I was referring to the interface of
XMLDocument, which has a load() method that dowloads and parses an xml
file.


What part of my above statement is still unclear to *you*?


I was trying to show a related feature that the origional poster may
not have been aware of. I wasn't talking about text/plain documents,
nor was I talking about the origional request. IT WAS A ***NOTE***,
NOT A DIRECT ALTERNATIVE!!!

Thishas nothing to do with the XMLHttpRequest.

[...]

That is your only valid point. But serving plain text als text/xml
(which AFAIK would be required for the mentioned XML parser) is
neither what the OP was looking for nor would it always work.


Sigh, that's not what I was talking about. It was a noted related
feature, not a direct responce to the OP's problem domain. Sometimes
people don't know what they want, or they want the wrong solution to a
problem. I certainly have written my fair share of hacks. Hasn't
everyone?

--
Jimmy Cerra

Warning: This post was not checked for spelling, grammar, or accuracy.
Please correct me, where appropiate. Thanks. :-)
Jul 23 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
3
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
3
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
0
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a...
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.