Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 17th, 2004, 12:29 PM
Authorized User
 
Join Date: Sep 2003
Location: Ipswich UK, , United Kingdom.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MattLeek
Default File Editing

Hello,
     Is it possible to edit files on a server with Javascript. If it is, could i do it on a remote server? For example i want to change just 5 numbers that are stored in it (highscores).

Thanks

Matt Leek

Matthew Leek
__________________
Thanks,
Matthew
Reply With Quote
  #2 (permalink)  
Old February 17th, 2004, 12:36 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

What exactly do you want to do? Do you want to edit a file on a different machine using client side script or use server side script to edit a file on the same server?

--

Joe
Reply With Quote
  #3 (permalink)  
Old February 17th, 2004, 02:18 PM
Authorized User
 
Join Date: Sep 2003
Location: Ipswich UK, , United Kingdom.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MattLeek
Default

Ok, i haven't really been doing this for long (a few hours really), but so far i have a page that uses asp to get the name and score that has been put in the url by the program. I then want to check their score against one stored on a different page and if it is higher, write over the original score.

I hope this helps

Matthew Leek
Reply With Quote
  #4 (permalink)  
Old February 18th, 2004, 05:09 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sounds like you want to use server side script then. Lets say you have an asp page that receives this url:
Code:
www.games.co.uk/myScores.asp?name=joe&score=100
.
In the asp page you have code (you said to use JavaScript):
Code:
var sName = Request("name") + "";
var iScore = parseInt(Request("score") + "", 10);
Now you also have a text file, stored in the same folder as the asp page. This file is name after the user, <username>.txt, and has their previous score
Code:
var ForReading = 1;
var ForWriting = 2;
var sFileName = Server.MapPath(sName + ".txt");
var oFso = new ActiveXObject("Scripting.FileSystemObject");
if (oFso.fileExists(sFileName))
{
  var oTS = oFso.OpenTextFile(sFileName, ForReading);
  var iLastScore = oTS.readLine();
  oTS.close();
  iLastScore = parseInt(iLastScore, 10);
  if (iLastScore < iScore)
  {
    oTS = oFso.OpenTextFile(sFileName, ForWriting);
    oTS.writeLine(iScore);
    oTS.close();
  }
}
else
{
  //Something wrong?
}
You can look at more on FileSystemObject on msdn.com. For example if the file does not exist because it's their first game you can create it from scratch.



--

Joe
Reply With Quote
  #5 (permalink)  
Old February 18th, 2004, 06:52 AM
Authorized User
 
Join Date: Sep 2003
Location: Ipswich UK, , United Kingdom.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MattLeek
Default

Thank you for that. I will check out msdn.com. There are a few things i dont quite understand there but im sure if i look them up it will be much easier to understand!

Thanks again :)

Matthew Leek
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Editing File Hind Java Basics 2 June 14th, 2006 07:04 PM
Editing a Text File mh VB.NET 1 December 8th, 2005 02:37 AM
Help.. Editing File.dll Aquilitto Pro PHP 1 September 5th, 2005 07:30 AM
Help.. Editing File.dll Aquilitto C++ Programming 2 August 30th, 2005 09:40 PM
Editing Excel File using oledb ctranjith General .NET 0 August 1st, 2005 09:41 AM



All times are GMT -4. The time now is 10:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.