本文整理汇总了PHP中curl_file_get_contents函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_file_get_contents函数的具体用法?PHP curl_file_get_contents怎么用?PHP curl_file_get_contents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_file_get_contents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload_img
/**
* 上传永久图片素材
* @param string $img
* @return string URL
*/
public static function upload_img($img = '', $access_token = '')
{
$url = self::post_url('media/uploadimg', $access_token);
//$img_path = str_replace('/', '\\', getcwd()."/uploads/build/whoami.png") ;
if (strpos($img, 'http') !== FALSE) {
$file = curl_file_get_contents($img);
$type = substr($img, strrpos($img, '.') + 1);
$img = '/uploads/build/tmp_wechat.' . $type;
file_put_contents('.' . $img, $file);
}
$img = str_replace('/', '\\', getcwd() . $img);
$ch = curl_init();
// 微信服务器CURL版本,低于PHP5.5
//$cfile = curl_file_create($img_path,'image/png','media');
$_data = array('media' => '@' . $img);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_SAFE_UPLOAD, FALSE);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $_data);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSLVERSION, 1);
//CURL_SSLVERSION_TLSv1
$return_data = curl_exec($ch);
curl_close($ch);
if (is_string($return_data)) {
$json = json_decode($return_data);
$return_data = empty($json->errcode) ? $json->url : false;
}
return $return_data;
}
示例2: get_content_by_url
function get_content_by_url($url)
{
$md5 = md5($url);
$content = S('file_content_' . $md5);
if (is_bool($content)) {
$content = curl_file_get_contents($url);
S('file_content_' . $md5, $content, 60 * 60);
}
return $content;
}
示例3: createRIFCSfromORCID
function createRIFCSfromORCID($identifier)
{
$target_uri = $this->orcidServiceURI . $identifier . "?callback=?";
echo $target_uri . " Is the URI </br>";
$response = curl_file_get_contents($target_uri);
print "<pre>";
print_r($response);
print "</pre>";
/* if ($response)
{
try
{
$sxml = @simplexml_load_string($response);
if (!$sxml) { throw new Exception("No valid data! " . $target_uri); }
$sxml->registerXPathNamespace("srw", "http://www.loc.gov/zing/srw/");
$count = $sxml->xpath("//srw:searchRetrieveResponse/srw:numberOfRecords");
if (is_array($count))
{
// Get the matching element
$count = array_pop($count);
$count = (int) $count;
}
if ($count)
{
$data = $sxml->xpath("//srw:recordData");
if (is_array($data))
{
// Get the matching element
$data = array_pop($data);
if ($data->registryObjects)
{
return $data->registryObjects->asXML();
}
else
{
echo "No registryObjects elements discovered inside SRW response: " . $identifier . NL;
}
}
}
else
{
echo "No matches from NLA SRU service on retrieving records for: " . $identifier . NL;
}
}
catch (Exception $e)
{
echo "Unable to load XML from NLA endpoint for ".$identifier.". Response: " . $e->getMessage() . NL;
}
} */
ob_flush();
flush();
return;
}
示例4: gmailContactEmail
function gmailContactEmail()
{
$client_id = '1092531224599.apps.googleusercontent.com';
$client_secret = 'HiLLtnhNibIDe8uPA0UVUVgW';
$redirect_uri = 'http://as.smurti.com/users/gmailContacts';
$max_results = 100;
$auth_code = $_GET["code"];
$fields = array('code' => urlencode($auth_code), 'client_id' => urlencode($client_id), 'client_secret' => urlencode($client_secret), 'redirect_uri' => urlencode($redirect_uri), 'grant_type' => urlencode('authorization_code'));
$post = '';
foreach ($fields as $key => $value) {
$post .= $key . '=' . $value . '&';
}
$post = rtrim($post, '&');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://accounts.google.com/o/oauth2/token');
curl_setopt($curl, CURLOPT_POST, 5);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
$result = curl_exec($curl);
curl_close($curl);
$response = json_decode($result);
$accesstoken = $response->access_token;
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results=' . $max_results . '&oauth_token=' . $accesstoken;
$xmlresponse = curl_file_get_contents($url);
if (strlen(stristr($xmlresponse, 'Authorization required')) > 0 && strlen(stristr($xmlresponse, 'Error ')) > 0) {
echo "<h2>OOPS !! Something went wrong. Please try reloading the page.</h2>";
exit;
}
$xml = new SimpleXMLElement($xmlresponse);
foreach ($xml->entry as $entry) {
$contact_Name[] = $entry->title;
}
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');
foreach ($result as $title) {
$contact_Email[] = $title->attributes()->address;
}
return $contact_Email;
}
示例5: DetectImage
function DetectImage($uri, $local = 0)
{
global $filterImage;
if ($filterImage) {
$exif_types = array(IMAGETYPE_GIF => 'image/gif', IMAGETYPE_JPEG => 'image/jpeg', IMAGETYPE_PNG => 'image/png');
$use_exif = function_exists('exif_imagetype');
// get image info
$mime = $use_exif && ($a = @exif_imagetype($uri)) && isset($exif_types[$a]) ? $exif_types[$a] : (($a = @getimagesize($uri)) ? $a['mime'] : null);
// valid mime type
if (empty($mime) or !preg_match('/(jpeg|jpg|gif|png)$/', $mime)) {
DefaultImage();
}
// detect image type 'png'
if (image_type_to_mime_type(IMAGETYPE_PNG) === $mime) {
$send = imagecreatefrompng($uri);
}
// detect image type 'jpeg'
if (image_type_to_mime_type(IMAGETYPE_JPEG) === $mime) {
$send = imagecreatefromjpeg($uri);
}
// detect image type 'gif'
if (image_type_to_mime_type(IMAGETYPE_GIF) === $mime) {
$send = imagecreatefromgif($uri);
}
}
// detect image from string
if ($local) {
$send = imagecreatefromstring(file_get_contents($uri));
} elseif (empty($send) && ($content = curl_file_get_contents($uri))) {
$send = imagecreatefromstring($content['content']);
}
// valid new image created
if (empty($send) or !is_resource($send)) {
DefaultImage();
}
// callback
return $send;
}
示例6: google_get_groups
function google_get_groups($token)
{
// retrieve groups
$url = 'https://www.google.com/m8/feeds/groups/default/full?alt=json&v=3.0&oauth_token=' . $token;
$xml_response = curl_file_get_contents($url);
$records = json_decode($xml_response, true);
//check for authentication errors
if ($records['error']['code']) {
header("Location: contact_auth.php?source=google&target=" . substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"], '/') + 1));
exit;
}
//create new array of groups
foreach ($records['feed']['entry'] as $group['number'] => $group) {
$group_id = substr($group['id']['$t'], strrpos($group['id']['$t'], "/") + 1);
$groups[$group_id]['name'] = $group['gContact$systemGroup']['id'] ? $group['gContact$systemGroup']['id'] : $group['title']['$t'];
$groups[$group_id]['count'] = 0;
unset($group_id);
}
unset($group);
//set account holder info
$_SESSION['contact_auth']['name'] = $records['feed']['author'][0]['name']['$t'];
$_SESSION['contact_auth']['email'] = $records['feed']['author'][0]['email']['$t'];
return $groups;
}
示例7: getIlceListFunc
function getIlceListFunc($sehir_id)
{
$sehir_id = (int) $sehir_id;
$ilceler_json = curl_file_get_contents('http://www.diyanet.gov.tr/PrayerTime/FillCity?itemId=' . $sehir_id);
if ($ilceler_json == '[]') {
return '[{"error":"Bu sehire ait ilceler bulunamadi."}]';
} else {
$ilceler_json = str_replace('"Selected":false,', '', $ilceler_json);
$ilceler_json = str_replace('"Selected":true,', '', $ilceler_json);
$ilceler_json = str_replace('"Text":', '"IlceAdi":', $ilceler_json);
$ilceler_json = str_replace('"Value":', '"IlceId":', $ilceler_json);
return $ilceler_json;
}
}
示例8: stdClass
} else {
$xmlPath = $di->getConfig()->configurationsDir . $configKey . '.xml';
}
if (!file_exists($xmlPath) && !curl_url_exists($xmlPath)) {
$app->response->setStatusCode(404, "Not Found");
$error = new stdClass();
$error->error = "La configuration « {$configuration} » n'existe pas!";
$app->response->send();
die(json_encode($error));
}
if ($encoding === "json") {
$app->response->setContentType('application/json; charset=UTF-8')->sendHeaders();
if (file_exists($xmlPath)) {
$element = simplexml_load_file($xmlPath, 'SimpleXMLElement', LIBXML_NOCDATA);
} else {
$element = simplexml_load_string(curl_file_get_contents($xmlPath), 'SimpleXMLElement', LIBXML_NOCDATA);
}
if ($element->getName() === "navigateur") {
//Gerer le cas des couches seulement avec un Id
//Retourner l'info pour creer correctement la couche cote client
$result = $element->xpath('//couche[boolean(@idbd)]');
$avertissement = null;
$debug = $app->getDI()->get("config")->application->debug;
foreach ($result as $couche) {
$coucheId = $couche->attributes()->idbd->__toString();
if (is_numeric($coucheId)) {
$coucheBd = IgoVueCouche::findFirst("id=" . $coucheId);
} else {
$coucheBd = IgoVueCouche::findFirst("mf_layer_name='" . $coucheId . "'");
}
if ($coucheBd === false) {
示例9: actionImportGoogleContacts
public function actionImportGoogleContacts()
{
if (isset($_GET["code"]) and $_GET["code"] != NULL) {
$client_id = '762232144092.apps.googleusercontent.com';
$client_secret = '5csDrunh7dufwm0nl-N6lyTw';
$redirect_uri = 'http://127.0.0.1/womv2.0/importcsv/default/importGoogleContacts';
$max_results = 1000;
$auth_code = $_GET["code"];
function curl_file_get_contents($url)
{
$curl = curl_init();
$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
curl_setopt($curl, CURLOPT_URL, $url);
//The URL to fetch. This can also be set when initializing a session with curl_init().
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
//TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
//The number of seconds to wait while trying to connect.
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
//The contents of the "User-Agent: " header to be used in a HTTP request.
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
//To follow any "Location: " header that the server sends as part of the HTTP header.
curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE);
//To automatically set the Referer: field in requests where it follows a Location: redirect.
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
//The maximum number of seconds to allow cURL functions to execute.
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
//To stop cURL from verifying the peer's certificate.
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$contents = curl_exec($curl);
curl_close($curl);
return $contents;
}
$fields = array('code' => urlencode($auth_code), 'client_id' => urlencode($client_id), 'client_secret' => urlencode($client_secret), 'redirect_uri' => urlencode($redirect_uri), 'grant_type' => urlencode('authorization_code'));
$post = '';
foreach ($fields as $key => $value) {
$post .= $key . '=' . $value . '&';
}
$post = rtrim($post, '&');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://accounts.google.com/o/oauth2/token');
curl_setopt($curl, CURLOPT_POST, 5);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$result = curl_exec($curl);
curl_close($curl);
$response = json_decode($result);
if ($response != NULL and isset($response->access_token)) {
$accesstoken = $response->access_token;
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results=' . $max_results . '&oauth_token=' . $accesstoken;
$xmlresponse = curl_file_get_contents($url);
if (strlen(stristr($xmlresponse, 'Authorization required')) > 0 && strlen(stristr($xmlresponse, 'Error ')) > 0) {
echo "<h2>OOPS !! Something went wrong. Please try reloading the page.</h2>";
exit;
}
$xml = new SimpleXMLElement($xmlresponse);
$contacts = array();
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');
/*$names = $xml->xpath('//gd:phoneNumber');
$i=0;
foreach($names as $name){
$contacts[$i++]['name'] = (string)$name;
}*/
$i = 0;
foreach ($result as $title) {
$contacts[$i++]['email'] = (string) $title->attributes()->address;
}
if (count($contacts) > 0) {
$addedCons = 0;
foreach ($contacts as $contact) {
$f_name = '';
$s_name = '';
$email = $contact['email'];
/*$parts = explode(' ',trim($contact['name']));
if(isset($parts[0])) $f_name=$parts[0];
if(isset($parts[1])) $s_name=$parts[1];*/
$con = new EmailContacts();
/*$con->first_name = $f_name;
$con->last_name = $s_name;*/
$con->email = $email;
$con->owner = Yii::app()->user->id;
$con->created = date('Y-m-d h:i:s');
if ($con->save()) {
$addedCons++;
}
}
Yii::app()->user->setFlash('message', $addedCons . ' contacts imported from Google');
} else {
Yii::app()->user->setFlash('message', 'No contacts found');
}
} else {
Yii::app()->user->setFlash('message', 'No response found');
}
} else {
Yii::app()->user->setFlash('message', 'Verification code not found');
}
$this->redirect('index');
//.........这里部分代码省略.........
示例10: SimpleXMLElement
$xslt->importStylesheet(new SimpleXMLElement($xsl));
return $xslt->transformToXml(new SimpleXMLElement($xml));
}
$GLOBALS['data'] = null;
$url = null;
if (isset($_REQUEST['url_metadata'])) {
$url = $_REQUEST['url_metadata'];
} else {
if (isset($_REQUEST['id'])) {
$url = "http://" . $GLOBALS['apps_config']['geonetwork']['host'] . "/geonetwork/srv/eng/csw?SERVICE=CSW&VERSION=2.0.2&REQUEST=GetRecordById&outputSchema=csw:IsoRecord&ID={$_REQUEST['id']}&elementSetName=full";
}
}
if (isset($url)) {
$parseUrl = parse_url($_SERVER['REQUEST_URI']);
$base = dirname($parseUrl['path']);
$xml = curl_file_get_contents($url);
if (isset($_REQUEST['full'])) {
$GLOBALS['data'] = transform($xml, fopen_file_get_contents("./xsl/bs_full.xsl"));
} else {
$GLOBALS['data'] = transform($xml, fopen_file_get_contents("./xsl/bs_full.xsl"));
}
$GLOBALS['data'] = str_replace("{base}", $base, $GLOBALS['data']);
//IncrementPopularity($_REQUEST['id']);
}
?>
<!DOCTYPE HTML>
<html xmlns:fb="http://ogp.me/ns/fb#" xmlns:og="http://ogp.me/ns#">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
示例11: estAuthentificationRequise
private function estAuthentificationRequise($configuration)
{
if (!isset($this->getDi()->getConfig()->application->authentification) || $this->getDi()->getConfig()->application->authentification == false) {
return false;
}
if (isset($this->getDi()->getConfig()->configurations[$configuration])) {
$xmlPath = $this->getDi()->getConfig()->configurations[$configuration];
} else {
$xmlPath = $this->getDi()->getConfig()->configurationsDir . $configuration . '.xml';
}
if (file_exists($xmlPath)) {
$element = simplexml_load_file($xmlPath);
} else {
//url externe
$element = simplexml_load_string(curl_file_get_contents($xmlPath));
}
if (isset($element->attributes()->authentification)) {
$authentification = $element->attributes()->authentification;
} else {
$authentification = "true";
// Est-ce qu'on devrait forcer l'authentification par defaut? En attendant de décider, on le force par défaut.
}
// Si la configuration demande que l'utilisateur soit authentifié et qu'il ne l'est pas encore, le rediriger vers la fenetre de connexion
if ($authentification == "true") {
return true;
} else {
return false;
}
}
示例12: file_put_contents
break;
}
}
file_put_contents($cookie_file, '<?php return ' . var_export($cookies, true) . ';');
$_cookie = '';
foreach ($cookies as $k => $v) {
$_cookie .= "{$k}={$v}; ";
}
array_pop($header);
$header[] = 'Cookie: ' . trim($_cookie);
}
$product['url'] = trim($url[1]);
$html = curl_file_get_contents($product['url'], null, $header, config('web.refresh_timeout'), $proxy, true);
}
} else {
$html = curl_file_get_contents($product['url'], null, $header, config('web.refresh_timeout'), $proxy);
}
if (!$html) {
json_return(null, 1, 'Load page\'s data fail, please retry.');
}
if (!$product['cover'] || !$product['title']) {
// preg product's title
preg_match('/<span id="productTitle".*?>(.*?)<\\/span>/is', $html, $title);
if (!empty($title[1])) {
$product['title'] = html_entity_decode(trim($title[1]));
}
// preg product's cover
preg_match('/data\\:image\\/jpeg;base64,(.+)/i', $html, $cover);
if (!empty($cover[0])) {
$product['cover'] = 1;
//trim($cover[0]);
示例13: curl_file_get_contents
<div id="sidemenu">
<?php
include 'setup_sidemenu.php';
?>
</div>
<?php
$setupModel = Setup::model()->findByPk(1);
//$request='http://rapportsoftware.co.uk/versions';
$update_url = $setupModel->version_update_url;
$request = $update_url . '/latest_stocksystem_version.txt';
//echo "<br>request = ".$request;
$available_version = curl_file_get_contents($request, true);
$current_version = Yii::app()->params['software_version'];
?>
<table style="width:40%;">
<tr>
<td style="vertical-align:top;"><h4>Version</h4></td>
<td style="vertical-align :top;"><?php
echo Yii::app()->params['software_version'];
?>
</td>
<td style="vertical-align :top;">
<?php
if ($available_version != $current_version) {
$step = 1;
//echo "Please delete all contents of update directory";
echo CHtml::button('Update', array('submit' => 'index.php?r=/Setup/showUpdateProgress&curr_step=' . $step));
//echo CHtml::button('Update',array($this->showUpdateProgress($step)));
示例14: uniqid
// Create a random file name for temporary kml and map file.
$randomFileName = uniqid();
$vecteurFilePath = $GLOBALS['apps_config']['impression']['imagepath'] . $randomFileName . ".kml";
$vecteurMapFilePath = $GLOBALS['apps_config']['impression']['imagepath'] . $randomFileName . ".map";
$vecteurTemplateMapFilePath = $GLOBALS['apps_config']['impression']['map_template'];
$mapTemplateFileHandler = fopen($vecteurTemplateMapFilePath, 'r') or die("can't open file");
$mapTemplateFileContent = fread($mapTemplateFileHandler, filesize($vecteurTemplateMapFilePath));
$kml = $_POST['vecteurs'];
//Check SVG
if (preg_match_all('/<Icon><href>([^<]+\\.svg)<\\/href><\\/Icon>/', $kml, $matches)) {
foreach ($matches[1] as $key => $value) {
$dir = $GLOBALS['apps_config']['impression']['imagepath'];
//Trouver le nom et l'extension
$name = substr($value, strrpos($value, '/') + 1);
//aller chercher le symbol
$svg = curl_file_get_contents($value);
$handle = fopen($dir . $randomFileName . $name, "w");
fwrite($handle, $svg);
fclose($handle);
//Ajout du symbol dans le Mapfile
$symbolTemplate = "#SYMBOL_TAG \n" . "SYMBOL \n" . " NAME \"" . $randomFileName . $name . "\" \n" . " TYPE svg \n" . " IMAGE \"" . $randomFileName . $name . "\" \n" . " END \n";
$mapTemplateFileContent = str_ireplace('#SYMBOL_TAG', $symbolTemplate, $mapTemplateFileContent);
//modification du kml pour faire référence au nom du symbol
$kml = str_ireplace($value, $randomFileName . $name, $kml);
}
}
// Read the template map file and replace the filename tag with the path of the kml file
$vecteurMapFileContent = str_replace("mapfilename", $vecteurMapFilePath, $mapTemplateFileContent);
$vecteurMapFileContent = str_replace("kmlfilename", $vecteurFilePath, $vecteurMapFileContent);
fclose($mapTemplateFileHandler);
// Write the KML File to disk.
示例15: get_full
/**
* Get orcid XML of orcid id, if access_token is not set, it will return public information
* @return object_xml
*/
function get_full()
{
$opts = array('method' => 'GET', 'header' => 'Accept: application/orcid+json');
$header = array("Accept:application/orcid+json; charset=utf-8");
if (!$this->get_orcid_id() && !$this->get_access_token()) {
return false;
} else {
$url = $this->api_uri . 'v1.1/' . $this->get_orcid_id() . '/orcid-profile/';
// $context = stream_context_create($opts);
if ($this->get_access_token()) {
$url .= '?access_token=' . $this->get_access_token();
}
// $result = @file_get_contents($url.'s', true, $context);
// $result = curl_post($url,'', array('header'=>'Accept: application/orcid+json'));
$result = curl_file_get_contents($url, $header);
$re = json_decode($result, true);
if (isset($re['error'])) {
return false;
} else {
return $result;
}
}
}