473,394 Members | 1,878 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,394 software developers and data experts.

Writing to a text file on the website server

I want to be able to write text data to a (preexisting) text file on my website.

have readup heaps, and tinkered around a bit,
and it seems this might actually be possible afterall,
(because of the aweful security risk it poses) at least with javascript.

Can someone clear this up for me, is it possible
(and if so, how) ?

Cheers
Mike
Sep 29 '06 #1
4 7693
acoder
16,027 Expert Mod 8TB
Not possible with JavaScript alone, but possible with Ajax. Use a server-side script to append to the file and use JavaScript to post to that script.
May 15 '08 #2
pronerd
392 Expert 256MB
and it seems this might actually be possible after all
How?



Can someone clear this up for me, is it possible
Acoder, as usual, is correct. JavaScript is a client side language. Meaning it runs on the client, in this case the browser. It can not write to disk on a remote server. It can not even run on the server. HTML and or JavaScript can be used to send a file to the server, but you would need server side code there to receive it and write it to disk for you.

If you know of some way around this we are all ears.
May 15 '08 #3
rnd me
427 Expert 256MB
How?




Acoder, as usual, is correct. JavaScript is a client side language. Meaning it runs on the client, in this case the browser. It can not write to disk on a remote server. It can not even run on the server. HTML and or JavaScript can be used to send a file to the server, but you would need server side code there to receive it and write it to disk for you.

If you know of some way around this we are all ears.
[HTML]


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>javascript-only file writing</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>javascript fileIO demo</h1>
<b>
javascript can use standard http methods like <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">GET, PUT, and DELETE</a> to create, modify, and manage files on a remote server. The only configuration needed on the server, is the allowance of public or user-based write permissions.

this can be done on window iis server by right-clicking a folder in the IIS web site folder-view.
chmod can be used on unix machines.

if you use apache, then you will need a bit of server-side code called a <a href="http://httpd.apache.org/docs/1.3/misc/FAQ.html#putsupport">put handler</a> to catch the PUT requests. (<a href="http://hpwww.ec-lyon.fr/~vincent/apache/mod_put.html">module here</a>)
</b>
<br />
<hr />
<br />

open <a href='newPage.htm' target="_blank">my new page</a> in a new tab/window.
<br />
<br />

<textarea rows='10' cols='80' id='userValue'>Hello World</textarea>
<br />
<br />


<input type='button' value='Save' onclick="doSave()" />

&nbsp;&nbsp;&nbsp;
<input type='button' value='Load' onclick="doLoad()" />

<script type='text/javascript'>


function el(tid) {return document.getElementById(tid);}

function IO(U, V) {
//LA MOD String Version. A tiny ajax library. by, DanDavis
var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
X.open(V ? 'PUT' : 'GET', U, !1);
X.setRequestHeader('Content-Type', 'text/html')
X.send(V ? V : '');
return X.responseText;}


function doSave(){
IO("newPage.htm" , el("userValue").value );
}

function doLoad(){
el("userValue").value = IO("newPage.htm");
}

</script>


</body>
</html>[/HTML]
May 16 '08 #4
acoder
16,027 Expert Mod 8TB
Interesting, though it could pose a security risk, so should be for trusted users only.

This could be the subject of an article (hint, hint ;))
May 16 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rob Meade | last post by:
Hi all, Ok - minor fly in my ointment... I have an application which was successfully writing data from submitted forms to a text file in a directory - in this case: /data/findata.txt ...
1
by: Joe Ehrenfeld via .NET 247 | last post by:
I ma having an issue saving a text file that is located on a remove server (Chase Bank) to one of my servers. I know that I have the file in the Srtream object but I just can't seem to get it to save...
6
by: Richard L Rosenheim | last post by:
I'm trying to write an error log from a web service. I'm getting an exception of "Access to the path {filename} is denied." when I attempt to create the file. I tried specifying the root...
4
by: Andyza | last post by:
I'm using FileSystemObject to open and write to a tab delimited text file. First, I connect to a database and select some data. Then I create the text file and insert each record in the text...
9
by: brett | last post by:
I have a main aspx file for my site and use web controls as includes for content. The url may look like this: www.abc.com/main.aspx?page1 I'd like to store content in a text file and...
5
by: chisty | last post by:
can any one tell how to write a text file inputs to different edit boxes using a button.....text file contain different data.displaying each data in different edit boxes using single button click
0
by: dineshchothe | last post by:
Hi, I want to upload a text file on Server(Tomcat) from client. Pls help me to do this, also give any example related to this if possible. Thnks in advance. Dinesh
17
by: NYXX | last post by:
I wanna know how its possible to clone this website. www.writesomething.net I just want the actual programming code and files. I'm going to ceate a fully interactive website for users to input...
7
by: Fuji | last post by:
Dear Sir, Why this code can't be ran in my Internet Explorer? Am I doing wrong in using ActiveXObjectScripting.FileSystemObject")? <html> <head><title>Reading/Writing Text File in...
0
by: karimkhan | last post by:
Hi everyone .. I want to upload the text file from my desktop to server . Text file is getting generated by some sensors and at every hour its getting updated . I want that it should also reflect...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.