summaryrefslogtreecommitdiffstats
path: root/lib/util.php
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2012-11-17 12:31:25 -0800
committerThomas Müller <thomas.mueller@tmit.eu>2012-11-17 12:31:25 -0800
commitac3e9627323b37fe1613b6879d5757241abac3ef (patch)
treec26c85e95eb52a9d07a60d926de4cea9efdfcc00 /lib/util.php
parent9e9bf20b07a274fee5ff2e29568e4929f488d459 (diff)
parentd2047a00cf0fa7383a6dd1834d3d3500f58b1931 (diff)
downloadnextcloud-server-ac3e9627323b37fe1613b6879d5757241abac3ef.tar.gz
nextcloud-server-ac3e9627323b37fe1613b6879d5757241abac3ef.zip
Merge pull request #375 from tdevos/master
Use curl to get remote file content
Diffstat (limited to 'lib/util.php')
-rwxr-xr-xlib/util.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/util.php b/lib/util.php
index da57b226ba0..725278a39e6 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -669,4 +669,43 @@ class OC_Util {
return false;
}
+
+ /**
+ * @Brief Get file content via curl.
+ * @param string $url Url to get content
+ * @return string of the response or false on error
+ * This function get the content of a page via curl, if curl is enabled.
+ * If not, file_get_element is used.
+ */
+
+ public static function getUrlContent($url){
+
+ if (function_exists('curl_init')) {
+
+ $curl = curl_init();
+
+ curl_setopt($curl, CURLOPT_HEADER, 0);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
+ curl_setopt($curl, CURLOPT_URL, $url);
+
+ $data = curl_exec($curl);
+ curl_close($curl);
+
+ } else {
+
+ $ctx = stream_context_create(
+ array(
+ 'http' => array(
+ 'timeout' => 10
+ )
+ )
+ );
+ $data=@file_get_contents($url, 0, $ctx);
+
+ }
+
+ return $data;
+ }
+
}