Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

save to local disk

Links for php scripts

Moderators: macek, egami, gesf

save to local disk

Postby milily » Sun Jun 29, 2003 9:35 pm

Hi all, I am learning PHP right now. Can PHP save data to LOCAL disk? After the user submits the form, I want to save the submitted file to local disk. Can php do this? I searched, but still no answer. If it can, could you give me any hint about this? Thank you very much for any help.

Helen
milily
New php-forum User
New php-forum User
 
Posts: 8
Joined: Sun Jun 29, 2003 12:39 pm
Location: Michigan, U.S.

Postby Redcircle » Sun Jun 29, 2003 11:45 pm

when you say local disk do you mean the server or the clients machine?
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby Joan Garnet » Mon Jun 30, 2003 3:30 am

Well,
php can do both things. Upload files and download files.
Now we need to know which one you need :D
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

local

Postby milily » Mon Jun 30, 2003 6:52 am

The "local" here I mean the users's machine, not the server. Thank you.
milily
New php-forum User
New php-forum User
 
Posts: 8
Joined: Sun Jun 29, 2003 12:39 pm
Location: Michigan, U.S.

Postby milily » Mon Jun 30, 2003 7:01 am

I don't want to upload or download files. What I want to do is after the user submit the form, save one copy of the answers on the desktop of the local disk. This also require the php can set the path of the file so the user can decide where to save it. Can php do this? Thank you very much.
milily
New php-forum User
New php-forum User
 
Posts: 8
Joined: Sun Jun 29, 2003 12:39 pm
Location: Michigan, U.S.

Postby Joan Garnet » Mon Jun 30, 2003 3:07 pm

PHP actions take place in the server.
To do such thing you will need another language.
I don't know if javascript can save files in the client's filesystem...
:?:
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Postby Redcircle » Thu Jul 03, 2003 7:28 am

Best thing I can reccomend is to email it or store it in a database for future viewing. You can also have it send file headers that will prompt the user to save to disk. But there no way to do it with PHP alone without some user intervention.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

reply: try vb

Postby nathanwebb6 » Sat Jul 05, 2003 5:15 pm

i dont know for definate, but visual basic can write to compuiters, so maybe that can write the info?
nathanwebb6
New php-forum User
New php-forum User
 
Posts: 27
Joined: Sat Jul 05, 2003 5:08 pm
Location: england uk

Postby cw4908 » Sun Aug 31, 2003 4:08 am

<html><head>
<SCRIPT LANGUAGE="JavaScript">
var password="theirpassword";
var name="username";
function WriteToFile()
{
var filename = "c://OurSiteData.txt";
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FileExists(filename))
{
var a, ForAppending, file;
ForAppending = 8;
file = fso.OpenTextFile(filename, ForWriting, false);
file.WriteLine(name);
file.WriteLine(password);
}
else
{
var file = fso.CreateTextFile(filename, true);
file.WriteLine(password);
file.WriteLine(name);
}
file.Close();
}
function ReadIt()
{
var filename = "c://data.txt";
if (confirm("Do you want to see what we put on your computer?"))
{
var fso, a, ForReading;
ForReading = 1;
fso = new ActiveXObject("Scripting.FileSystemObject");
file = fso.OpenTextFile(filename, ForReading, false);
var name = file.readline();
var password = file.readline();
file.Close();
document.write(name + "<br>");
document.write(password);
}
}
</SCRIPT>
</head>
<body onload="WriteToFile();ReadIt()">
</body>
</html>


________________________________
Notes:

This does NOT work in Netscape, without a bit of rigging, which I have not included becuase of security issues. When using this (It is ActiveX, and as the others here posted, browsers have a security issue with you writing on user's system), the user (who can disallow ActiveX - they get an error) or can have it allowed (not normal, but if set in security settings as allowed the script works silently) or they can have it prompted for (this is defualt in IE). If it is set to the default prompt for ActiveX, they see the following prompt:

Image

You can have as many variables as you want, and they can be derived from JavaScript,PHP,whatever. Just make sure that you include the BOTH occasions of "file.WriteLine(variable);" to write the file, and the occasion of "var name = file.readline();" (var 'name' can be named anything as normal) for each individual variable if you choose to use the ReadIt() function on the same page or another.
The "if (confirm(............." is just incase you want to prompt them about what you put (note it writing it to the page with "document.write(..);" ) ...What you do with it once read is up to you!

Just remember, a small percentage of folks will get errors, most will get that alert, and NS users will get nothing but errors. Want to stop the NS errors and have this work in NS? Search for "Netscape PrivilegeManager" or "Netscape Security Privaleges" in any search.

Also, note: Where it has the word "ForWriting"...IF the file already exist, they will recieve an error on any browser as it tries to overwrite it, generally. You can replace this with "ForAppending", BUT the ForAppending adds the lines to the end of the file, and would later cuase a mess reading it in your scripts.

Search for "ActiveX write textfile", for more info.
cw4908
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sun Aug 31, 2003 3:06 am


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.