For
security reasons, web browser code
cannot write to your file system.
But it can ask a web
server to write
to the server's file system instead.
Now, web servers don't normally run
on a regular PC — but there is a way ...
If you have the knowledge and the money,
I recommend you to set up an
offline PC
where you
disable all internet functionality
after you installed all the needed software,
e.g. web browsers and especially
XAMPP.
XAMPP is a developer's platform for writing
server-side internet applications.
It
simulates a web server on your localhost.
The safest way to use it is on an offline PC.
XAMPP stands for:
X = Windows or Linux (WAMPP/LAMPP)
A = Apache web server
M = MySQL or MariaDB database server
P = PHP server programming language
P = Perl server programming language
Setting it up
correctly can be a bit of a
challenge, but it's well worth the effort.
Now you can save and load actual
files,
as soon as you implemented a
BSB
protocol for doing so. Such as this:
1. The
Eas 4B browser code:
save'to
fn -- file name
d -- data
:
send ("save" fn MAP:d)
TO'SERVER:"BSB.php" send 1
/
delete'file
fn -- file name
:
save'to:fn
/
load'from
fn -- file name
:
TO'SERVER:"BSB.php" ("load" fn) 1
/
! SERVER'REPLY
r FROM'JSON:SERVER'REPLY
? r[0]="loaded"
fn r[1] -- file name
d FROM'MAP:r[2] -- data
--+ use the loaded data
/
/
The save request is sent as
JSON,
which is the last parameter "1",
but the data is MAPed, because
MAP is a more compact format.
The server expects requests starting
with a
command field, such as "save",
usually followed by one or more
payload fields. For "save", those are
the file name and the data to be saved.
BSB is
asynchronous, therefore
loading a file consists of two steps:
1.
request a file by load'from
2.
receive the file in !SERVER'REPLY
Server replies use the same
structure
as BSB requests: command + payload.
2. The
PHP server code:
(Save it as BSB.php.)
<?php
r(file_get_contents("php://input"));
function r($r){
$r=json_decode($r);
if(!$r)exit;
switch("$r[0]-".(count($r)-1)){
case"save-2":
$f="savefiles/$r[1]";
$p=dirname($f);
if(!is_file($p))mkdir($p,0777,1);
file_put_contents($f,$r[2]);
break;
case"load-1":
$f="savefiles/$r[1]";
$d=file_get_contents($f);
if($d===false)$d="";
$r=["loaded",$r[1],$d];
echo json_encode($r);
break;
}
}
?>
This whole PHP code, by the way, could be
replaced by the following
Eas 4S code
(Eas 4S is still in development):
!
r FROM'BROWSER
? r[0];"-";r? = "save-2"
SAVE:r[1] r[2]
\ "load-1"
SAY:("loaded" r[1] LOAD:r[1])
/
/