We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › text file on server
Page Index Toggle Pages: 1
text file on server (Read 2685 times)
text file on server
Apr 29th, 2005, 11:34pm
 
hi all

i have two apps, one which writes to and one which reads from a text file. i'm hoping to stick this all in the same folder on my server.

i read in the old forum that i shouldn't need to sign the app to get this to work but the app which writes can't open the file (does in p55) when both are in the same folder on my hard drive.

do i need to specify the URL when on the server? maybe the folder when on my hard drive? if so how?

any advice greatly appreciated - having this assessed for uni soon!

cheers - rene.

Re: text file on server
Reply #1 - May 1st, 2005, 5:05pm
 
sorry - posted a little prematurely on that one. trying to get the apps to run on my hard drive first: the app i have that reads the file works as i use loadstrings() and just specify the path with "./file.txt"

but for the other app i had to use FileWriter() so that i could append to the end of the file. according to my googling "/file.txt" should work to access a file in the same folder but it doesn't. here's my code:

try
  {
 file = new FileWriter("/sites.txt", true);
 file.write("\n"+output,0,output.length()+1);
 file.close();
 println("Added Link: " + output);
       }
    catch(Exception e)
  {
    println("Error: Can't open file!");
   }

hope someone can help but i guess this should be in the integration forum as this is a java q? will wait before double posting.

cheers.

Re: text file on server
Reply #2 - May 1st, 2005, 7:56pm
 
since a processing sketch (or java applet) runs only on a user's machine, it can't save anything because it has no concept of the files that are stored on your server.

so in order to make this work, you'd need to make your sketch communicate through a cgi script (there were examples of doing this via php on the old board, you might do a search), which runs on your server and can accept the file being uploaded by your sketch.
Re: text file on server
Reply #3 - May 2nd, 2005, 3:00pm
 
ok. so does that mean that when i used loadstrings("./file.txt") that it was only reading from a copy of the file that it copied from my server to the users machine at runtime?
Re: text file on server
Reply #4 - May 2nd, 2005, 5:31pm
 
something like that.. your server can provide files, but it can't save them back without additional help.

when you make your sketch, you'll have file.txt in the "data" folder. when you export the sketch, the data folder gets packed up along with the code to run your sketch. then when a person visits the web page with the sketch, that stuff gets sent to the user as one package and then run. web servers are mostly one way in that sense.
Page Index Toggle Pages: 1