Click to See Complete Forum and Search --> : Write to the server


MainMa
08-28-2003, 04:14 AM
Is it possible to write "New visitor! " to the file "statistics.txt", which is on the server, each time the page "index.htm" (at the same server) is visited by somebody?

Server supports JavaScript and SSI.

Thank you,
MainMa

AdamGundry
08-28-2003, 05:13 AM
IIRC, this should work as long as your server runs *NIX and you have appropriate permissions. Place it at the top of your index page, and rename the file to activate SSI (presumably to .shtml):

<!--#exec cmd="echo New visitor! >> statistics.txt" -->

Adam

MainMa
08-28-2003, 12:15 PM
Originally posted by AdamGundry
IIRC, this should work as long as your server runs *NIX and you have appropriate permissions. Place it at the top of your index page, and rename the file to activate SSI (presumably to .shtml):

<!--#exec cmd="echo New visitor! >> statistics.txt" -->

Adam

When load, the server write:

[There is an error when executing SSI directive: verify the syntax]

Sorry for my english (I translated the server's message myself and I am not sure that the sentence is correct) :)

AdamGundry
08-28-2003, 03:59 PM
I'm afraid I'm not that knowledgeable on SSI, but you could check the following points:[list=1] Do you have the necessary permissions to use SSI exec?
Have you set the file permissions of statistics.txt to be writeable by others (on Linux, chmod 666)?[/list=1]
Adam

P.S. Just checked, and the SSI should work on DOS as well as *NIX.

MainMa
08-29-2003, 03:51 AM
Originally posted by AdamGundry
Have you set the file permissions of statistics.txt to be writeable by others (on Linux, chmod 666)?..

How must I do it?

AdamGundry
08-29-2003, 04:10 AM
In order for a file to be editable by SSI or another server-side language, it needs to have certain permissions set - specifically, it needs to be writeable by "others". If you are transferring the files via FTP, your FTP program should allow you to change permissions (see its documentation). Otherwise, contact your web host for information on changing permissions.

Adam

P.S. If your FTP software requires a number for the permission settings, use 666 (read/writeable by all).

MainMa
08-29-2003, 04:27 AM
OK, If I manage FTP with Windows Explorer, how must I do it?
(I have Windows XP)

AdamGundry
08-29-2003, 04:35 AM
This article should help: http://www.cdmcss.com/Resources/Web_info/Web_Development/w2kftp.shtml#perms

You need to tick all the boxes in the first two columns (read and write).

Adam

P.S. Explorer is not really a very good FTP program, you would be better off getting a dedicated program such as SmartFTP (http://www.smartftp.com).

MainMa
08-29-2003, 04:53 AM
Thank you. I changed rights to the file, but now, when I load the page which must modify this file, my IE writes that it doesn't know the keyword 'File'. :(

AdamGundry
08-29-2003, 04:58 AM
Can you please post a link to the page, and the code behind it, so I can figure out what is causing the error.

Thanks

Adam

MainMa
08-29-2003, 05:04 AM
The page is:

http://mapictures.by.ru/readfile.htm

The file to read/write is:

http://mapictures.by.ru/data.txt

I attached an image which shows an error I see when I run the script.

AdamGundry
08-29-2003, 05:11 AM
This is Javascript, unrelated to the SSI code earlier. It will not work, because it uses a non-existent object called "File" - I presume you want to read/write a file on the server using Javascript, which is not possible. Use server-side code for file access.

Adam

MainMa
08-29-2003, 05:13 AM
And what is the way?

AdamGundry
08-29-2003, 05:16 AM
If your JS does what I think it wants to, you should be able to use something like this SSI:

<!--#exec cmd="echo abc > data.txt" -->

This overwrites the file "data.txt" with the string "abc". If you would like to append the string to the end of the file, use two greater than signs (>>).

Adam

MainMa
08-29-2003, 05:26 AM
The file "data.txt" stays like it was before.
Sorry... :(

PS. There is a progress:
The server does not write

[There is an error when executing SSI directive: verify the syntax]

like it did before.

AdamGundry
08-29-2003, 05:29 AM
As I said before, I'm no SSI expert, so I suggest you post in the CGI forum, or I can help you more if you use PHP.

Adam

MainMa
08-29-2003, 05:35 AM
Thank you.
My server doesn't support PHP, so, I will ask somebody at CGI forum.

Thank you again,
Good bye.