diff --git a/lib/filelib.php b/lib/filelib.php
index 92ba502..aa43f3b 100644
--- a/lib/filelib.php
+++ b/lib/filelib.php
@@ -79,9 +79,10 @@ function get_file_url($path, $options=null, $type='coursefile') {
  *   usually happens if the remote server is completely down (default 20 seconds);
  *   may not work when using proxy
  * @param bool $skipcertverify If true, the peer's SSL certificate will not be checked. Only use this when already in a trusted location.
+ * @param bool $setreferer If true, the HTTP Referer field will be set to the URL of the site.
  * @return mixed false if request failed or content of the file as string if ok.
  */
-function download_file_content($url, $headers=null, $postdata=null, $fullresponse=false, $timeout=300, $connecttimeout=20, $skipcertverify=false) {
+function download_file_content($url, $headers=null, $postdata=null, $fullresponse=false, $timeout=300, $connecttimeout=20, $skipcertverify=false, $setreferer=false) {
     global $CFG;
 
     // some extra security
@@ -119,6 +120,9 @@ function download_file_content($url, $headers=null, $postdata=null, $fullrespons
             $snoopy->proxy_user     = $CFG->proxyuser;
             $snoopy->proxy_password = $CFG->proxypassword;
         }
+        if ($setreferer) {
+            $snoopy->referer   = $CFG->wwwroot;
+        }
         if (is_array($headers) ) {
             $client->rawheaders = $headers;
         }
@@ -199,6 +203,9 @@ function download_file_content($url, $headers=null, $postdata=null, $fullrespons
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
     }
+    if ($setreferer) {
+        curl_setopt($ch, CURLOPT_REFERER, $CFG->wwwroot);
+    }
 
     if (!empty($CFG->proxyhost)) {
         // SOCKS supported in PHP5 only
