You need to create a script that writes the string “text” to a file located on the client’s computer.
Added.
Here is an example of my code
& lt ;?
$ file = fopen ("D: /file.txt", "a +");
$ str = "Hello, world! \ n \ r";
if (! $ file)
{
echo ("Error opening file");
}
else
{
fputs ($ file, $ str);
}
fclose ($ file);
? & gt;
Writing
Error opening file.
Answer 1, authority 100%
Files cannot be created on the client computer.
Answer 2, authority 60%
PHP scripts are executed on the server side, so create, open, write, etc. files on the client side cannot be done using PHP.
In your example, “D: /file.txt” means that the server will try to open this file on its D drive, not on the client.
Answer 3, authority 20%
I almost misunderstood your question, but here’s an example – creating a file using php:
& lt ;?
$ fp = fopen ("File_name.txt", "w");
fwrite ($ fp, "text");
fclose ($ fp);
? & gt;
Answer 4
Nobody will let your site do anything with the local machine for security reasons. The answer is unambiguous, you can’t do that.
Answer 5
To save data on the client’s machine, you can use the storages intended for this:
-
cookie
setcookie ('last_visited', time ());
-
localStorage (sessionStorage, etc)
$ now = time (); echo "& lt; script & gt; localStorage.last_visited = {$ now}; & lt; / script & gt;";
Answer 6
You can also use this option:
$ f = fopen ("file.txt", "a");
fputs ($ f, "text or variable");
fclose ($ f);
Answer 7
- Working with files
- ftp_get – download a file from an FTP server