标签: file-get-contents

php中的file_get_contents或curl?

在PHP中使用file_get_contentscurl应该使用哪个来发出HTTP请求?

如果file_get_contents能完成这项工作,是否需要使用curl?使用curl似乎需要更多的线条.

例如:

卷曲:

$ch = curl_init('http://www.website.com/myfile.php'); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $content); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$output = curl_exec ($ch); 
curl_close ($ch); 
Run Code Online (Sandbox Code Playgroud)

的file_get_contents:

$output = file_get_contents('http://www.website.com/myfile.php'.$content); 
Run Code Online (Sandbox Code Playgroud)

php curl file-get-contents

8
推荐指数
3
解决办法
2万
查看次数

php file_get_contents授权标头

任何人都可以解释为什么私有bitbucket存储库的授权功能在我的本地机器上运行(运行PHP版本5.3.17),但未在我的远程服务器上授权(运行PHP版本5.3.20)

我本身并没有得到错误 - 我只是从bitbucket得到了一个"禁止"的回应.但是从我的本地服务器运行一切都很好.

function bitBucketConnect($url){
    global $bitPassword;
    global $bitUsername;
    $context = stream_context_create(array(
     'http' => array(
       'header' => "Authorization: Basic " . base64_encode("$bitUsername:$bitPassword")
       )
    ));

 // Make the request
 return file_get_contents($url, false, $context);
 }
Run Code Online (Sandbox Code Playgroud)

php file-get-contents

8
推荐指数
1
解决办法
2万
查看次数

file_get_contents不适用于某些网址

file_get_contents在PHP中使用.在下面的代码中,第一个URL工作正常,但第二个不起作用.


$URL = "http://test6473.blogspot.com";
$domain = file_get_contents($URL);
print_r($domain);


$add_url= "http://adfoc.us/1575051";
$add_domain = file_get_contents($add_url);
echo $add_domain;

Run Code Online (Sandbox Code Playgroud)

为什么第二个不起作用的任何建议?

php curl file-get-contents

8
推荐指数
1
解决办法
3万
查看次数

allow_url_fopen安全吗?

file_get_contents()鉴于URL,我目前正在使用获取网页的标题.在wamp上,这非常好用.但是,当我把它转移到我的网络服务器时,我遇到了一个问题,它引导我得到这个答案.(这是设置allow_url_fopen1).

设置此功能是否存在重大安全风险?如果是,是否有其他方法可以从URL本身获取网页标题?

(另外,不确定标签,所以如果合适,请随意添加/删除!)

编辑(1):进一步的研究引导我提出这个问题,它几乎说它也是一个风险,并且如果应用程序不需要它就禁用它.不幸的是,这并没有告诉我所涉及的风险.

编辑(2):快速注释,我将使用此功能与用户输入(URL),而不是内部,这就是为什么我想确保绝对没有涉及安全风险

php file-get-contents

8
推荐指数
2
解决办法
1万
查看次数

php file_get_contents($ url)&变成&

我试图像这样向coinbase api提出请求

$url = "https://api.gdax.com/products/BTC-USD/candles?start=".date($format,$starting_date)."&end=".date($format,$ending_date)."&granularity=".$granularity;
Run Code Online (Sandbox Code Playgroud)

然后我把file_get_contents($url)它传递进去,但它给了我一个错误

file_get_contents(https://api.gdax.com/products/BTC-USD/candles?start=2015-05-07&end=2015-05-08&granularity=900):无法打开流:HTTP请求失败!HTTP/1.1 400错误请求.

问题当然是'&'变成'&'时.

php url file-get-contents url-encoding ampersand

8
推荐指数
2
解决办法
8547
查看次数

弹性搜索和Codeigniter(PHP)

我正在尝试使用带有Codeigniter框架的ElasticSearch.

我所做的只是安装ElasticSearch并将在Web上找到的一个好的PHP库复制(:P)到CI库:

    class Elasticsearch {

  public $config_file = 'elasticsearch';
  public $index;

  function __construct($index = false){
      $CI =& get_instance();
      $CI->config->load($this->config_file);
      $this->server = $CI->config->item('es_server');

  }

  function call($path, $http = array()){
    if (!$this->index) throw new Exception('$this->index needs a value');
    return json_decode(file_get_contents($this->server . '/' . $this->index . '/' . $path, NULL, stream_context_create(array('http' => $http))));
  }

  //curl -X PUT http://localhost:9200/{INDEX}/
  function create(){
     $this->call(NULL, array('method' => 'PUT'));
  }

  //curl -X DELETE http://localhost:9200/{INDEX}/
  function drop(){
     $this->call(NULL, array('method' => 'DELETE'));
  }

  //curl -X GET http://localhost:9200/{INDEX}/_status
  function status(){
    return …
Run Code Online (Sandbox Code Playgroud)

php codeigniter file-get-contents elasticsearch

7
推荐指数
1
解决办法
1万
查看次数

file_get_contents适用于本地但不适用于服务器

可能重复:
file_get_contents()错误

处理连接到Instagram API的脚本以从特定标签获取照片.它在Local上工作正常,但在服务器上我得到错误.

警告:在第19行的/storage/content/91/103391/instaboll.nu/public_html/instagram.php中,allow_url_fopen = 0在服务器配置中禁用了file_get_contents():https://包装器.

第19行看起来是这样的:
$ contents = file_get_contents(" https://api.instagram.com/v1/tags/ $ tag/media/recent?client_id = $ client_id");

有任何想法吗?

已搜索过这个并找到一些推荐curl的帖子,但不知道如何继续.

php file-get-contents

7
推荐指数
1
解决办法
3万
查看次数

Urlencode和file_get_contents

我们有一个像http://site.s3.amazonaws.com/images/some image @name.jpg里面的网址$string

我正在尝试做什么(是的,网址周围有一个空格):

$string = urlencode(trim($string));
$string_data = file_get_contents($string);
Run Code Online (Sandbox Code Playgroud)

我得到了什么(@也被替换):

file_get_contents(http%3A%2F%2Fsite.s3.amazonaws.com%2Fimages%2Fsome+image+@name.jpg)[function.file-get-contents]: failed to open stream: No such file or directory

如果您复制/粘贴http://site.s3.amazonaws.com/images/some image @name.jpg到浏览器地址栏中,图像将会打开.

有什么不好以及如何解决这个问题?

php file urlencode file-get-contents

7
推荐指数
2
解决办法
2万
查看次数

php方法只读取部分远程文件

我正在处理file_get_contents远程文件并处理它们.不幸的是,文件非常大,我只需要一个小段.我确切地知道我需要读取什么偏移量和它的长度但是阅读php手册似乎file_get_contents只有在本地文件上才有可能.

有没有下载整个文件的方法?

php file-get-contents

7
推荐指数
1
解决办法
1031
查看次数

PHP标头 - 内容类型:image/jpeg - 不适用于Internet Explorer

在构建HTML模板或修改网站时,我们都讨厌Internet Explorer.我最近构建了一个PHP图像脚本来隐藏URL的位置.它适用于Firefox,Chrome甚至Safari.

Internet Explorer拒绝显示PHP脚本中的图像.它甚至没有给出破碎的图像图标.只是空白方块.

Android也有同样的问题,但我可以在另一个时间到达并且可能是相关的.

这是我的图像脚本代码:

$image_id = $_GET['id'];

include "mysql_connect.php";
$sql = "SELECT * FROM images WHERE code='$image_id'";
$result = mysql_query($sql);
$r=mysql_fetch_array($result);

$imagepath=$r['path'];

// Produce proper Image
header("Content-type: image/jpeg");

echo file_get_contents("$imagepath");
Run Code Online (Sandbox Code Playgroud)

我在谷歌和这个网站上搜索得很高.无法找到解释Internet Explorer未显示图像的原因.

任何帮助是极大的赞赏.

php header file-get-contents

7
推荐指数
1
解决办法
6万
查看次数