Page 1 of 1

Possible ? Can PHP write a File on the Clients Hard Disk?

Posted: Tue Dec 07, 2004 1:50 pm
by asterinex
Following Problem :

I have a project on the client Sides(c++) that queries my database. I do this by the Libcurl Library biy sending a URL with POST. So far So good . Now I need the Result of the query back in my C++ Application. Is it possible that PHP Writes the Result of the Query in een Textfile direct on the clients Hard-Disk ?

Posted: Tue Dec 07, 2004 1:56 pm
by rehfeld
because php runs on the server, it cant do anything on the client side.

but, you could have php output a command to your client,
and then your program on the client side could interpret it.

Posted: Tue Dec 07, 2004 2:06 pm
by asterinex
Thanks, can you give me a bit more details please. What functions can I use in PHP en how do you think my c - programm can interprete it?

Posted: Tue Dec 07, 2004 2:08 pm
by rehfeld
did you write the C++ code?

Posted: Tue Dec 07, 2004 2:11 pm
by asterinex
Yes, I wrote the c programm, using Libcurl . So till now it was easy for me ?
Why ?

Posted: Tue Dec 07, 2004 2:21 pm
by rehfeld
well basically what you need to do is have your c++ program look for commands everytime it contacts php.

obviously you already have some way to communicate
w/ and fetch data from php, so its just a matter of
deciding what you want to be the signal for the c++ prog to identify as php telling it to save.

like for example, i assume your sending a command to php,
and then php interprets that command and queries the database, and then
php returns the result to the c++ program. you basically just need to make this works both ways


a simple way could be to have c++ check if the response contained a header called "X-Save"

so in php, if php decides its time for the client to save, it would do

Code: Select all

header('X-Save: true');
and your c++ prog just checks for the existance of that header everytime it talks w/ php.
if it can find that header in the response from php, then it saves the file.

you dont need to use headers to do this, i was just giving an example

Posted: Tue Dec 07, 2004 2:27 pm
by asterinex
Thanks a lot! What you mean I think is : C++ -> PHP -> Query DB-> PHP Writes results in file on server -> PHP Sends message to c++ -> C++ Downloads the File from Server ?

Is it possible to let Javascript write the result of a PHP query on the Clients Hard-Disk? Because Javascript is on the clients Side ?

Posted: Tue Dec 07, 2004 2:41 pm
by rehfeld
i dont think javascript can do that.
imagine the security problems if js could write or read from a clients harddisk.
it maybe possible if the javascript is loaded from the client side, and not from a website, but im not sure.


but yeah, you got the idea

C++ contacts http://yoursite.org/communicator.php?qu ... a_it_wants
php fetches result from database,
if php thinks its time for the client to save the file, it sends a X_SAVE header
php outputs results of db query using echo or whatever

c++ receives response, and looks for X-save
if it finds x-save, it saves the data. otherwise it just uses the data and throws it away when its done or whatever



question though, why do you need php to decide if the client should save the file?
i would think that would be something the client or the c++ app would determine?

Posted: Tue Dec 07, 2004 2:48 pm
by asterinex
Yes you are right. I will work in C++, with a timer. Lets Say Every 2 minutes the programm sends a request to the server to query the database. So every 2 minutes there is a file that is created. So I can theoratically download the file directly after it is created by PHP, instead waiting till PHP sends the X-SAVE. So what i mean is that I think that I don“t need the X_save command.