Click to See Complete Forum and Search --> : txt file, for reading only,


cacalex
05-15-2003, 11:09 AM
What if i have an txt file that contain, by example, an option select.

And what if i want to "read" this txt file that already exist ???

I Have 1 web page, desiged to "read" the option select, in txt file from differents folders.

i'm not sure if the fso method will work
(in fact, i can't make it work, without no error message...)

Is this possible ????
:confused:

Nevermore
05-15-2003, 11:30 AM
Unless everyone who is going to see your site is going to have a copy of your txt file on their computer, you will have to use server side scripts.

Jona
05-15-2003, 11:34 AM
You cannot use ActiveX and the FSO object on a Web page unless it is on the user's local machine. Servers do not generate these object properly, and this is for security. Use server-side languages to accomplish reading, writing, appending, or any other methods that deal with the FSO object.

cacalex
05-15-2003, 12:22 PM
and this mean i'll have to use php, or what ???

Jona
05-15-2003, 12:29 PM
You would use one of the following (links go to respective forums):

ASP (http://forums.webdeveloper.com/forumdisplay.php?s=&forumid=9)
CGI (Perl) (http://forums.webdeveloper.com/forumdisplay.php?s=&forumid=4)
PHP (http://forums.webdeveloper.com/forumdisplay.php?s=&forumid=16)

cacalex
05-15-2003, 12:32 PM
once more, Jona and Cijori,

you make my life easier !


Thanks !

Jona
05-15-2003, 12:33 PM
I think that's what this forum is for.... :rolleyes:

LOL

khaki
05-15-2003, 12:41 PM
hi cacalex...

here is an example from one of my ASP pages (and i know that it works because i pulled it directly from a working page :) ):
(oh... and this code also maintains the integrity of carriage returns in the original file... in case that is important for you)

<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("textFile.txt"), 1)
str = f.ReadAll
str = Replace(str, vbCrLf, (vbCrLf & "<br>"), 1, -1)
Response.Write(str)
Response.Write "<br>"
f.Close
Set f=Nothing
Set fs=Nothing
%>

;) k

Jona
05-15-2003, 12:44 PM
khaki, I learn a lot from you.... So, in ASP, methods don't require ()? In JS, it'd be ReadAll();. Hmm... close() instead of Close.. lol Different. No wonder JS confuses you sometimes! lol

Also, I thought you had to use Dim fs, f, str before you could use Set. Or was that just in Visual BASIC (6.0)?

khaki
05-15-2003, 12:55 PM
No wonder JS confuses you sometimes! uh-huh... it confuses me endlessly :rolleyes:

oh... good catch on the Dim
(i Dimmed a lot in my page and stripped them all out for my example...
including the one for the example :eek: )

Dim them (as Jona points-out)

a bit Dim...
:rolleyes: k

cacalex
05-15-2003, 12:56 PM
Whoo pals !

Don't confuse me even more !

Could someone provide me an working example
(PHP, ASP, or whatever...) ???

I'm pretty good with JS, but unfamilliar to server side language...

If someone could help me with this, i'm pretty sure it is on this forum !!!

send this to ajodoin@bdtca.com

Thanks !!!

khaki
05-15-2003, 01:08 PM
this is a working example (ASP).

just copy and paste this into a blank page...
change the text file name from textFile.txt to whatever your file is named...
save it as ASP...

and it will write your text file (as long as the text file is on the server AND your server supports ASP)
test it and see if it works for you as-is...

<%
Dim fs
Dim f
Dim str
' they could all be on 1 line, but...
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("textFile.txt"), 1)
str = f.ReadAll
str = Replace(str, vbCrLf, (vbCrLf & "<br>"), 1, -1)
Response.Write(str)
Response.Write "<br>"
f.Close
Set f=Nothing
Set fs=Nothing
%>

(i Dimmed it the "long" way so as not to add further confusion. sorry about that first time :rolleyes: )

;) k

cacalex
05-15-2003, 01:13 PM
Thanks !

I'm testing it right now !

(Be sure i'll give you news of my try !!!)

Jona
05-15-2003, 01:14 PM
See? I'm not Dim.... lol... khaki, you're not Dim either. It's a common mistake, and I'm sure we're both glad I caught it. ;)

AdamGundry
05-15-2003, 01:16 PM
Here's a working example in PHP (demonstrating how it is a much better langauge :p ):

<?php
$text_array = file("textfile.txt");
$text = implode("", $text_array);
print nl2br($text);
?>

Adam

AdamGundry
05-15-2003, 01:17 PM
Ah, what Dim people. Just use PHP (no dims at all) or Pascal (the much more elegant var). :D

Adam

Jona
05-15-2003, 01:21 PM
nl2br.... That means new line (\n) converts to <br> tags... Yeah, Adam, that's a good way to do it (rather than splitting through all the \n's and converting them manually through a loop).

I must admit, PHP is a much simpler language.

Adam, in Perl, you use my $var for a global variable, in Javascript it's var varName, in ASP it's Dim var, but in PHP... Is there a statement for global variables? Or are they automatically global?

AdamGundry
05-15-2003, 01:25 PM
You either use the global statement in a function to make a variable outside that function's scope accessible, or use the $GLOBALS array.

Adam

Jona
05-15-2003, 01:28 PM
Oh yeah, duh. ;)

In the words of Jar Jar Binks: "Meesa no understandin what yousa sayin!" lol (BTW, I do understand in case Jar Jar was unclear. lol)

khaki
05-15-2003, 01:50 PM
Here's a working example in PHP (demonstrating how it is a much better langauge the only thing that i understand about PHP is the "?"
(that's right up my alley. lol)

... so...
that did everything that the ASP version did?

what's "implode" (and what is the first argument... which appears to be empty, but i'm sure it means "empty")?

Can you explain that line... in English.... (and there is no need to translate it into a Star Wars language... since Jona already seems to understand it :) and i don't understand Star Wars languages any better than i understand PHP :rolleyes: )?

thank u

;) k

Nevermore
05-15-2003, 01:53 PM
If I remember rightly, implode is quite like JavaScript's split() backwars. It even takes similiar arguments. It glues elements of an array together.

Jona
05-15-2003, 02:10 PM
<?php
$text_array = file("textfile.txt"); // set the variable, "$text_array" to the file: textfile.txt
$text = implode("", $text_array); // implode the string. See: http://www.php.net/manual/en/function.implode.php
print nl2br($text); //convert all \n's to <br> tags so that it displays properly in HTML format
?>

cacalex
05-16-2003, 08:18 AM
Hey !

You do a lot of chat without me !!

Thanks to all of you.

Now that i have assimilate all those foggy serveur script things, my code(s) is working !

In ASP AND in PHP ! (i've test both...)

Name it, and it is done !

Can't believe it !
Of all those forum out there, this is the best !

See you (pretty soon) !

khaki
05-16-2003, 08:40 AM
You do a lot of chat without me !! Your obviously new around here :) lol

I do a lot of chatting PERIOD! :rolleyes:

Glad you got your scripts working (both?!! lucky you.... you got options.)

beginning to feel a bit of php-envy....
;) k

Jona
05-16-2003, 11:15 AM
lol khaki. I think learning ASP is a lot harder than learning PHP.... I mean a lot harder... ;)

cacalex
05-16-2003, 11:19 AM
Hey !

If the PHP beginner i am have been able to do it, i guess everyone could !

khaki
05-16-2003, 11:26 AM
it's not ability that keeps me from using PHP...
it's access :(

i just don't have access to a server that supports it (so... i'll stick with ASP... and maybe some day - if i find myself on a server that supports it - i'll fiddle with PHP)

ASP serves me well though
(but a girl can never have enough skills y'know... so i was just feeling sorry for myself... that's all :) )

;) k

Jona
05-16-2003, 12:56 PM
There are a few free servers that support it that you can use for testing (which is what I do): http://members.lycos.co.uk/ and http://t35.com/ T35.com servers unmetered bandwidth and space! Plus, they only show about one popup ad every time you visit the site (not every page). And it also comes with a MySQL database...

Nevermore
05-16-2003, 01:00 PM
I also use Lycos.co.uk for testing. They are really good, but now that I'm buying new hosting I should finally have enough storage space to test on a subdoamain. (What do you think, will 1.5 GB do the trick?!?

Jona
05-16-2003, 01:05 PM
LOL. I think that'd be enough, but you never know.... lol

Nevermore
05-16-2003, 01:07 PM
I dunno... I might just about manage!

:D :) :D