-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.php
More file actions
101 lines (87 loc) · 1.96 KB
/
main.php
File metadata and controls
101 lines (87 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<html>
<head>
<title>small clipboard</title>
<style>
textarea {
width:320px;
height:240px;
padding: 0;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<h1>clipboard</h1>
<?php
$dir_for_content = "/home/fibonacci/public_html/scb/temp_clipboard/";
$character_pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
$max_code_length = 7;
function generate_code($message)
{
global $character_pool, $max_code_length;
$poolSize = strlen($character_pool);
$code = "";
for($i = 0; $i < $poolSize && $i < $max_code_length ; $i++)
{
$code .= $character_pool{rand(0,$poolSize)};
}
return $code;
}
function generate_clipboard_file($fileName, $content)
{
global $dir_for_content;
$fh = fopen($dir_for_content.$fileName, "w");
fwrite($fh, $content);
fclose($fh);
}
function loadClipedMessage($code)
{
global $dir_for_content;
$filePath = $dir_for_content.$code;
if(!file_exists($filePath))
{
return;
}
$savedMessage = file_get_contents($filePath, FILE_USE_INCLUDE_PATH);
unlink($filePath);
return $savedMessage;
}
$recievedMessage = $_POST["message"];
$recievedCode = $_GET["c"];
if($recievedCode)
{
echo "<h3>Content</h3>";
$clipedMessage = loadClipedMessage($recievedCode);
if($clipedMessage)
{
echo "<textarea>$clipedMessage</textarea>";
}
else
{
echo "###### empty ######</br>";
}
}
else if($recievedMessage)
{
echo "<h3>Content</h3>";
echo "<textarea>$recievedMessage</textarea>";
$generatedCode = generate_code($recievedMessage);
generate_clipboard_file($generatedCode, $recievedMessage);
$url = "http://openmaya.com/scb/?c=".$generatedCode;
echo "<h4>Temporary url</h4>";
echo $url;
}
else
{
?>
<form method="post" action="./">
<textarea name="message"></textarea><br/>
<input type="submit" value="copy"></input>
</form>
<?
}
?>
<br/><br/>
<a href="./">clear</a>
</body>
</html>