-
Notifications
You must be signed in to change notification settings - Fork 0
/
save.php
executable file
·39 lines (33 loc) · 1.3 KB
/
save.php
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
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
$markdown = $_POST['markdown'];
preg_match_all("/path: \"\/(.*)\/\"/", $markdown, $output_array);
$dir = date("Y-m-d") . "-" . $output_array[1][0];
mkdir("../gatsby/pages/" . $dir, 0755);
$file = fopen("../gatsby/pages/" . $dir . "/index.md","w");
fwrite($file, $markdown);
fclose($file);
$arr = file("../gatsby/pages/" . $dir . "/index.md");
$arr[0] = trim($arr[0]) . "\n";
$arr[1] = trim($arr[1]) . "\n";
$arr[2] = trim($arr[2]) . "\n";
$arr[3] = trim($arr[3]) . "\n";
$arr[4] = trim($arr[4]) . "\n";
$arr[5] = trim($arr[5]) . "\n";
file_put_contents("../gatsby/pages/" . $dir . "/index.md", implode($arr));
$i = 0;
foreach($_FILES as $file){
$filename = $_FILES["UploadedImage" . $i]["name"];
move_uploaded_file($_FILES["UploadedImage" . $i]["tmp_name"], "../gatsby/pages/" . $dir . '/' . $filename);
$i++;
}
shell_exec('(cd ../gatsby/; gatsby build)');
?>