PDA

View Full Version : Save To Disk?



Cyber
January 20th, 2002, 15:18
is there a function in Javascript or PHP so that the user can save a certain page to disk? (sorta like when you right-click)


like (the thing is suposed to be a folder):



[ n ] Save this page to disk
[ [_] ]



is there any way to write a function to do that?

thanks!!

niv
January 20th, 2002, 15:36
Not really. That's why we having something called MIME types. Read up on them and implement them in .htaccess files.

Cyber
January 20th, 2002, 15:39
ugh...so theres no way to save a file to disk?? NUTS

Pedroz
January 20th, 2002, 16:50
Try this:

<script language="JavaScript">
function saveas()
{
document.execCommand('SaveAs');
}
</script>
<a href="#" onClick="javascript:saveas()">Save this page</a>

Cyber
January 20th, 2002, 17:24
does it work on macs and netscape?

Dusty
January 20th, 2002, 17:27
Does it work on macs and netscape?No.

It would make more sense to just write a script to open the file and print it back out with an altered header, which would force a "Save As..." dialog to popup.

Cyber
January 20th, 2002, 17:30
how would i do that?

Dusty
January 20th, 2002, 17:38
#!perl

print "Content-type: download\n";
print "Content-disposition: attachment; filename=filename.here\n\n";
open(FILE,"<path_to_file");
while(<FILE>){
print $_;
}
close(FILE);

Cyber
January 20th, 2002, 17:42
in PHP how do i do it, im not good at translating

niv
January 20th, 2002, 17:48
PHP automatically spits out Content-type: text/html...

Cyber
January 20th, 2002, 17:57
got it. if any one wants to use it, here: