Page 1 of 1
saving file on the user's computer
Posted: Sat May 30, 2009 3:21 pm
by TheStoryTeller
Hello, I need to process some data and save it. I am forbidden to save it on my own database - so I will not.
Is there a way to save a file on the user's comptuer (forget about how I can get it back for now)?
Re: saving file on the user's computer
Posted: Sat May 30, 2009 4:12 pm
by Darhazer
How much data you need to save? If it is small amount of data, you can use cookie. You can save a file also just asking the user to download it... you just need to send the correct headers and output the data... the browser will ask the user to save the file and will save it. Then you have to ask the user to upload the file in order to load the data back.
Re: saving file on the user's computer
Posted: Sat May 30, 2009 4:18 pm
by jaoudestudios
TheStoryTeller wrote:Is there a way to save a file on the user's comptuer
Isnt that what viruses do?
Re: saving file on the user's computer
Posted: Sat May 30, 2009 5:05 pm
by TheStoryTeller
Darhazer wrote:How much data you need to save? If it is small amount of data, you can use cookie. You can save a file also just asking the user to download it... you just need to send the correct headers and output the data... the browser will ask the user to save the file and will save it. Then you have to ask the user to upload the file in order to load the data back.
ok, both methods sound good, I think I like the first one better. The data i'm collecting is a simple list (probably text file in a certain format or it could be XML) but it's size can be between 5 to 20 KB, depends on the user. is that range of size is "cookie-able"?
and about the headers.. I never really got them down propely.. if your'e aware of any good tutorial/example on the subject (other than the php.net site..) which i'll miss if I simply google it - I would love to know about it.
Thank You.
Re: saving file on the user's computer
Posted: Sat May 30, 2009 5:08 pm
by TheStoryTeller
jaoudestudios wrote:TheStoryTeller wrote:Is there a way to save a file on the user's comptuer
Isnt that what viruses do?
hmmm.. but I don't want to build a virus.. are you implying that it's impossible? or maybe I need the user's permission?
Re: saving file on the user's computer
Posted: Sun May 31, 2009 2:59 am
by jaoudestudios
you will need the users permission, unless you use a cookie as Darhazer suggested, but then you are limited with how much data you can save.
Re: saving file on the user's computer
Posted: Sun May 31, 2009 7:13 am
by Darhazer
More than 4 KB is not suitable for cookies, altough some web browsers and/or web server can allow it.
As for the download, I have written such few times, I have no code in front of me (I can send one when I'm in the office, just P.M. me), but generally you need Content-type: application/ocstream, and Content-dispossition: attachment.
I think using this keywords you can find a working example
Also, you may be interested in how much data can flash store in the SharedObject, if flash is suitable for your needs. The last suggestion is going trough ActiveX control - if user permit it, it have access to the filesystem.
And one more think - you can try using a service to save the data on a web host, and set only id in the cookie, or switch the hosting provider, so you can save at the server.
Good luck!