在相同目录内新建content.txt、index.php,然后将以下代码复制到index.php中
原理:每秒写入一次文件到content.txt
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$content = $_POST['content'];
file_put_contents('content.txt', $content);
exit;
}
$content = file_get_contents('content.txt');
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>网络粘贴板</title>
<link rel="shortcut icon" href="https://img.meituan.net/video/28612b2cf8c65f3e50a89519f1aa41a1178282.png">
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.3/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-image: url('https://img.meituan.net/video/4536167c4d01d7225c84b7247590c8ab1124921.jpg');
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.container {
background: rgba(255, 255, 255, 0.8);
border-radius: 15px;
padding: 20px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
width: 90%;
max-width: 800px;
}
#editor {
width: 100%;
height: 400px;
resize: none;
}
</style>
<script>
function saveContent() {
const content = document.getElementById('editor').value;
fetch('index.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'content=' + encodeURIComponent(content),
});
}
setInterval(saveContent, 1000);
</script>
</head>
<body>
<div class="container">
<textarea id="editor" class="form-control"><?php echo htmlspecialchars($content); ?></textarea>
</div>
</body>
</html>