Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
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
 
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
 
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
 
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




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





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