Here ya go, this gets the job done in far less php code, letting php handle the json, added some basic checks with success and error messages.
Far less error prone when you use the php functions instead of string concatenating json yourself.
You were also exploding on single type of line break when there are 3 possibilities.
You had a header redirect back to the page itself after writing the json file and then proceeded to run checks on variables that would always be empty because of the redirect to decide if you needed the example data and made it so the user entered data would never fill the boxes after submitting.
You linked to a non-existent css file.
Your table had an extra <tr> hanging out and some other nitpick stuff. Didn't use placeholder for example data, etc...
Your tinfoil link generation depends on the php file being a specific name, otherwise it would create a bad link for use with tinfoil.
Very easy to break the page with special characters as well...
Learning some basic php functions goes a long way, doing things in some weird early php4 fashion is poop.
Good day.
PHP:
<?
$tinfoil_array = array();
$message = $links = $linksNSP = NULL;
if (isset($_POST['message'])) {
$message = trim($_POST['message']);
$message = htmlspecialchars($message);
$tinfoil_array['success'] = $message;
}
if (isset($_POST['linksNSP'])) {
$linksNSP = trim($_POST['linksNSP']);
$linksNSP = htmlspecialchars($linksNSP);
$tinfoil_array['files'] = preg_split('/\r\n|\r|\n/', $linksNSP);
}
if (isset($_POST['links'])) {
$links = trim($_POST['links']);
$links = htmlspecialchars($links);
$tinfoil_array['directories'] = preg_split('/\r\n|\r|\n/', $links);
}
if (!empty($links) || !empty($linksNSP)) {
file_put_contents('index.json', json_encode($tinfoil_array, JSON_UNESCAPED_SLASHES));
echo "<div id='json_success'>Json file updated!</div><br />";
}
if (count($_POST) > 0 && empty($_POST['links']) && empty($_POST['linksNSP'])) {
echo "<div id='json_error'>Json file not updated, no links provided!</div><br />";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<title>Tinfoil</title>
<style>
#link_info {
font-weight: bold;
text-decoration: underline;
clear: both;
}
#link_text {
background-color: yellow;
clear: both;
float: left;
}
#link_text, #link {
display: none;
}
#json_success {
background-color: lightgreen;
clear: both;
}
#json_error {
background-color: lightpink;
clear: both;
}
</style>
</head>
<body>
<form method="post">
<table>
<tr>
<td width="200">Welcome message</td>
<td><textarea id="message" name="message" rows="5" cols="70" placeholder="Put your welcome message here"><?= $message ?></textarea></td>
</tr>
<tr>
<td>One GDrive <b>NSP</b><br />One per line<br />No folder<br />No maximum</td>
<td><textarea id="linksNSP" name="linksNSP" rows="10" cols="125" placeholder="https://drive.google.com/open?id=xxxxxxxxxxxxxxxx
https://drive.google.com/open?id=yyyyyyyyyyyyyyyy
https://drive.google.com/open?id=zzzzzzzzzzzzzzzz"><?= $linksNSP ?></textarea></td>
</tr>
<tr>
<td>One GDrive <b>FOLDER</b><br />One per line<br />No single nsp<br />No maximum</td>
<td><textarea id="links" name="links" rows="10" cols="125" placeholder="https://drive.google.com/open?id=xxxxxxxxxxxxxxxx
https://drive.google.com/open?id=yyyyyyyyyyyyyyyy
https://drive.google.com/open?id=zzzzzzzzzzzzzzzz"><?= $links ?></textarea></td>
</tr>
<tr>
<td>
<input type="submit" value="Create Json">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
<br />
<div id="link_info">Copy this link in the file browser of HBG Shop/Tinfoil</div>
<div id="link_text"></div>
<a href="index.json" id="link"></a>
<script>
var link = document.getElementById('link').href;
document.getElementById('link_text').innerHTML = link;
document.getElementById('link_text').style.display = "block";
</script>
</body>
</html>