summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2015-12-11 16:30:41 +0000
committerJoe Robinson <joe@lc8n.com>2015-12-11 16:30:41 +0000
commit19723c932cad1d7f29db90316d63bcb87564d876 (patch)
tree9178b7316efdbb74541b3fc0aa81d81b0c7da688
parent2dafdedfe29aee7ed19d141bbe0953e94b4a499b (diff)
Add option to send notification to a URL when a file is uploaded
-rw-r--r--config.php.example6
-rw-r--r--upload_file.php18
2 files changed, 24 insertions, 0 deletions
diff --git a/config.php.example b/config.php.example
index e45ff35..43303a2 100644
--- a/config.php.example
+++ b/config.php.example
@@ -18,4 +18,10 @@
# An array of filenames to omit from the index
$indexignore = array(".htaccess", "config.php", "index.php", "upload_file.php", "upload.html");
+
+ # An URL to send a POST to when an upload is successful
+ $nofificationurl = "http://tghost.co.uk/blaupload"
+
+ #The IRC channel notified by uploads when using the notification URL
+ $notificationchannel = "theblueroom"
?>
diff --git a/upload_file.php b/upload_file.php
index 890078a..3f35524 100644
--- 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($notificationurl)) {
+ send_upload_notification($fileurl);
+ }
}
}
+
+function send_upload_notification($fileurl) {
+ $data = array('url' => $fileurl, 'channel' => $notificationchannel);
+
+ $options = array(
+ 'http' => array(
+ 'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
+ "X-Blaears-Event: blaupload",
+ 'method' => 'POST',
+ 'content' => http_build_query($data),
+ ),
+ );
+ $context = stream_context_create($options);
+ file_get_contents($url, false, $context);
+}
?>
</p>
<p>