mirror of
https://github.com/jvsteiner/send-note.git
synced 2026-07-22 11:20:26 +00:00
Add upload example script
This commit is contained in:
parent
43b6fda1d2
commit
553ebe3b83
1 changed files with 21 additions and 0 deletions
21
update-example.php
Normal file
21
update-example.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
$whitelist = ['html', 'css', 'jpg', 'png', 'ttf', 'otf', 'woff', 'woff2'];
|
||||
$secret = 'some_fancy_secret';
|
||||
|
||||
$data = json_decode(file_get_contents('php://input'));
|
||||
|
||||
if (! hash_equals($data->auth, hash('sha256', $data->nonce . $secret))) {
|
||||
http_response_code(404);
|
||||
exit();
|
||||
}
|
||||
|
||||
$file = explode('.', $data->filename);
|
||||
$file[0] = preg_replace("/[^a-z0-9]/", '', $file[0]);
|
||||
if (count($file) === 2 && in_array($file[1], $whitelist) && ! empty($file[0])) {
|
||||
if ($data->encoding === 'base64') {
|
||||
// Decode uploaded images
|
||||
$data->content = base64_decode($data->content);
|
||||
}
|
||||
file_put_contents(__DIR__ . "/$file[0].$file[1]", $data->content);
|
||||
}
|
||||
Loading…
Reference in a new issue