标签: file-get-contents

获取网址内容PHP

我想把一个URL的内容放在一个字符串和过程中.但是,我有一个问题.

我收到此错误:

Warning: file_get_contents(http://www.findchips.com/avail?part=74ls244) [function.file-get-contents]: failed to open stream: Redirection limit reached,
Run Code Online (Sandbox Code Playgroud)

我听说这是由于页面保护和标题,cookie和东西.我怎样才能覆盖它?

我也尝试过替代品,比如fread和fopen,但我想我只是不知道该怎么做.

有人可以帮我吗?

php url curl file-get-contents

20
推荐指数
3
解决办法
13万
查看次数

如何解决错误"[ErrorException] file_get_contents(/var/www/laravel/.env):无法打开流:没有这样的文件或目录"?

我在我的机器上使用Ubuntu 14.04.我安装了composer,然后在文档根目录中进行了laravel,即/ var/www

我还将-R 777 persmission给目录/ var/www中的文件夹laravel

然后我使用cd/var/www/laravel进入目录laravel并运行以下命令php artisan并且我在那里看到所有可用的命令.

然后我输入php artisan key:generate并得到错误

[ErrorException]  file_get_contents(/var/www/laravel/.env): failed to open stream: No such file or directory
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 在这里我实际上卡住了,有人可以在这方面帮助我吗?

谢谢.

php file-get-contents laravel ubuntu-14.04 laravel-5.2

20
推荐指数
3
解决办法
4万
查看次数

如何在变量中执行和获取.php文件的内容?

我想在其他页面上的变量中获取.php文件的内容.

我有两个文件,myfile1.phpmyfile2.php.

myfile2.php

<?PHP
    $myvar="prashant"; // 
    echo $myvar;
?>
Run Code Online (Sandbox Code Playgroud)

现在我想在myfile1.php中的变量中获取myfile2.php回显的值,我尝试了以下方式,但它也采用了包括php tag()在内的所有内容.

<?PHP
    $root_var .= file_get_contents($_SERVER['DOCUMENT_ROOT']."/myfile2.php", true);
?>
Run Code Online (Sandbox Code Playgroud)

请告诉我如何将一个PHP文件返回的内容转换为另一个PHP文件中定义的变量.

谢谢

php return file file-get-contents

18
推荐指数
6
解决办法
5万
查看次数

使用file_get_contents将JSON转换为PHP数组

我试图使用杂志api获取以下json内容.json的输出是这样的.我希望下面的json转换为php数组.

{
"bpath": "http://www.sampledomain.com/",
"clist": [
    {
        "cid": "11",
        "display_type": "grid",
        "ctitle": "abc",
        "acount": "71",
        "alist": [
            {
                "aid": "6865",
                "adate": "2 Hours ago",
                "atitle": "test",
                "adesc": "test desc",
                "aimg": "",
                "aurl": "?nid=6865",
                "weburl": "news.php?nid=6865",
                "cmtcount": "0"
            },

            {
                "aid": "6857",
                "adate": "20 Hours ago",
                "atitle": "test1",
      "adesc": "test desc1",
      "aimg": "",
                "aurl": "?nid=6857",
                "weburl": "news.php?nid=6857",
                "cmtcount": "0"
            }
        ]
    },
    {
        "cid": "1",
        "display_type": "grid",
        "ctitle": "test1",
  "acount": "2354",
        "alist": [
            {
                "aid": "6851",
                "adate": "1 Days ago",
                "atitle": …
Run Code Online (Sandbox Code Playgroud)

php arrays json file-get-contents

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

使用cURL检索网站HTML页面,其中包含当前会话和安全页面上的cookie数据

问题完全修订于:2月19日

我想要的东西(简而言之):

我想使用cURL获取一个HTML页面,该页面使用用户登录进行保护(在cURL请求时,用户已登录并拥有该页面的权限).

更详细:

情况是用户位于index.php?w=2344&y=lalala&x=something受保护的网页上(通过安全脚本class.Firewizz.Security.php).在该页面上有一个"print as pdf"按钮.这会将用户发送getPDF.php到此页面查看请求来源的页面,并使用cURL获取该页面,并将该输出作为PDF打印发送到浏览器.

但是现在我在页面中设置页面变量static,getPDF.php所以它不检查引用者,我100%确定它尝试获取的页面是正确的.

此外,输出只是按原样回显,并且尚未转换为PDF,因此不会干扰问题.

预期输出现在与用户进入页面时的输出相同.除了不是这种情况,用户什么也得不到.

我们知道什么?我们知道$_SESSION数据没有被发送到cURL,我知道这是因为我回应$_SESSION了输出文件中的数据,表示它们是空的.

经过大量的尝试,我们仍然没有解决方案,仍然没有'$ _SESSION'数据.

我不想以任何方式破坏安全脚本,因此解决方案"删除ini_set('session.use_only_cookies', 1);不是我想要的".

根据要求(专用于帮助)我可以发送完整的脚本文件,但我会在下面发布相关的片段.

class.Firewizz.Security.php

<?php

/*
 * Firewizz UserLogin
 */

namespace Firewizz;



class Security
{

     // Start the session, with Cookie data
    public function Start_Secure_Session()
    {
        // Forces sessions to only use cookies.
        ini_set('session.use_only_cookies', 1);

        // Gets current cookies params
        $cookieParams = session_get_cookie_params();

        // Set Cookie Params
        session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $this->isHTTPS, …
Run Code Online (Sandbox Code Playgroud)

php cookies session curl file-get-contents

18
推荐指数
1
解决办法
1694
查看次数

如何在PHP中获取文件的内容类型?

我正在使用PHP发送带附件的电子邮件.附件可以是几种不同文件类型中的任何一种(pdf,txt,doc,swf等).

首先,脚本使用"file_get_contents"获取文件.

之后,脚本在标题中回响:

Content-Type: <?php echo $the_content_type; ?>; name="<?php echo $the_file_name; ?>"
Run Code Online (Sandbox Code Playgroud)

如何为$ the_content_type设置正确的值?

php email content-type file-get-contents

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

使用文件获取内容或卷曲

我被要求使用一个简单的facebook api来返回返回json字符串的工作中的喜欢或分享的数量.现在,因为我要为大量链接执行此操作,哪一个更好:

使用file_get_contents或cURL.

它们似乎都返回相同的结果,cURL似乎使用起来更复杂,但它们之间的区别是什么.为什么大多数人建议使用cURL而不是file_get_contents?在我运行可能需要一整天才能处理的api之前,我希望得到反馈.

php curl file-get-contents

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

Google云端硬盘GET_CONTENT意图读取文件

我有一个Android上的应用程序,使用像Dropbox这样的云存储进行一些文件共享.开始分享我扔android.intent.action.SEND.在显示的列表中,我看到了Google云端硬盘应用(之前已安装),因此我尝试将文件发送给它 - 它运行正常,该文件显示在云端硬盘列表中.

然后,在另一台设备上我想读取这个文件.我抛出 android.intent.action.GET_CONTENT意图,选择驱动器,然后不知道如何获取文件.我收到这样的Uri:

content://com.google.android.apps.docs.files/exposed_content/6jn9cnzdJbDywpza%2BlW3aA%3D%3D%0A%3BRV%2FaV94o%2FCcW4HGBYArtwOdHqt%2BrsYO4WmHcs6QWSVwp%2FXogkRAgit7prTnfp00a%0A
Run Code Online (Sandbox Code Playgroud)

我不知道如何转换为物理文件路径.我怎么能从这里得到文件内容?

我在内容提供商周围玩,可以获取文件名,但不是完整路径或其他任何内容.

对于Dropbox,我得到file://风格uri,笔直,简单,效果很好.

android file-get-contents google-drive-api

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

PHP - 假设application/x-www-form-urlencoded,未指定Content-type

2天我在我的服务器上遇到PHP脚本问题.我什么都没改变,突然间它再也没用了.

这是代码:

$query = http_build_query($data);
$options = array(
    'http' => array(
        'header' => "Content-Type: application/x-www-form-urlencoded\r\n".
                    "Content-Length: ".strlen($query)."\r\n",     
        'method'  => "POST",
        'content' => $query,
    ),
);
$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n",'method'  => 'POST',
        'content' => http_build_query($data),));
$contexts = stream_context_create($opts);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $contexts, -1, 40000);
Run Code Online (Sandbox Code Playgroud)

我收到这些错误消息:

注意:file_get_contents():假设application/x-www-form-urlencoded in,未指定Content-type

警告:file_get_contents(https://mobile.dsbcontrol.de):无法打开流:HTTP请求失败!HTTP/1.1 500内部服务器错误

但是当我在本地尝试脚本时,它可以很好地工作.

php file-get-contents

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

Laravel5 Json获取文件内容

我现在正在使用Laravel-5,我刚刚创建了一个JSON名为test(test.json)的文件.我的问题是:

  1. 我应该把我的JSON文件放在哪里?
  2. 我如何使用file_get_contents并指向我想要的那个文件?

这是我尝试过的,这显然是错误的:

$string = file_get_contents("../json/test.json");   
$json_file = json_decode($string, true);
Run Code Online (Sandbox Code Playgroud)

非常感谢您的帮助!

json file-get-contents laravel

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