diff options
author | Luke Bratch <luke@bratch.co.uk> | 2015-12-12 15:06:57 +0000 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2015-12-12 15:06:57 +0000 |
commit | f9c44edcef62e0987109d0bb3922e819d346d86f (patch) | |
tree | 96f72f100899d66e68a13432f65969df10489c7c /upload_file.php | |
parent | 2dafdedfe29aee7ed19d141bbe0953e94b4a499b (diff) | |
parent | 615164ec271a64dbd3007270470fb32880191b0e (diff) |
Merge branch 'blaears_post' into 'master'
Send a POST to blaears when a file is uploaded
Blaears now listens on /blaupload for POSTs containing 'url' and 'channel', and will post those URLs to that channel.
I've added a config value $posturl for the URL to post to - if this is not set then nothing will be done.
If it is set, then it will send a POST containing the uploaded file URL and the channel set in $postchannel in the config.
I'm not sure on best practice for global variables in PHP. I passed them in as function arguments, but we could also use 'global $posturl, $postchannel' instead.
See merge request !2
Diffstat (limited to 'upload_file.php')
-rwxr-xr-x[-rw-r--r--] | upload_file.php | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/upload_file.php b/upload_file.php index 890078a..f1ed597 100644..100755 --- a/upload_file.php +++ b/upload_file.php @@ -51,8 +51,26 @@ if ($_FILES["file"]["error"] > 0) { $fileurl = "$url" . $_FILES["file"]["name"]; echo "URL: <a href=\"$fileurl\">$fileurl</a><br>"; echo "Size: " . size_readable($_FILES["file"]["size"], null, "bi"); + if (isset($posturl)) { + send_upload_notification($fileurl, $posturl, $postchannel); + } } } + +function send_upload_notification($fileurl, $posturl, $channel) { + $data = array('url' => $fileurl, 'channel' => $channel); + + $options = array( + 'http' => array( + 'header' => "Content-type: application/x-www-form-urlencoded\r\n" . + "X-Blaears-Event: blaupload\r\n", + 'method' => 'POST', + 'content' => http_build_query($data), + ), + ); + $context = stream_context_create($options); + file_get_contents($posturl, false, $context); +} ?> </p> <p> |