-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave.php
27 lines (23 loc) · 813 Bytes
/
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
<?php
define('MAX_FILE_LIMIT', 1024 * 1024 * 2);//2 Megabytes max html file size
function sanitizeFileName($fileName)
{
//sanitize, remove double dot .. and remove get parameters if any
$fileName = __DIR__ . '/' . preg_replace('@\?.*$@' , '', preg_replace('@\.{2,}@' , '', preg_replace('@[^\/\\a-zA-Z0-9\-\._]@', '', $fileName)));
return $fileName;
}
$html = "";
if (isset($_POST['startTemplateUrl']) && !empty($_POST['startTemplateUrl']))
{
$startTemplateUrl = sanitizeFileName($_POST['startTemplateUrl']);
$html = file_get_contents($startTemplateUrl);
} else if (isset($_POST['html']))
{
$html = substr($_POST['html'], 0, MAX_FILE_LIMIT);
}
$fileName = sanitizeFileName($_POST['file']);
if (file_put_contents($fileName, $html)) {
echo $fileName;
} else {
echo 'Error saving file ' . $fileName;
}