php - 文件获取内容(): Failed to enable crypto

标签 php yii2

当我尝试从谷歌获取图片时,它为一次搜索提供了 4 张图片,但由于图片大小,我无法获取一些图片。这样我就会收到类似

的错误

"file_get_contents(): Failed to enable crypto"

有什么解决办法吗? 这是我的代码

    <?php
    use frontend\models\Giftinterests;
    use yii\amazonproductapi\AmazonProductAPI;
    use yii\helpers\Url;
    use yii\web\NotFoundHttpException;
    use yii\image\ImageDriver;

    $sql_1 = 'SELECT * FROM `tn_gift_interests` where `gift_interest_status`="1" order by `gift_interest_id` ASC';
    $Query_Gift = Giftinterests::findBySql($sql_1)->all();

    $sql_2="TRUNCATE `tn_gift_google_image`";
    $query_1 = Yii::$app->db->createCommand($sql_2)->execute();




    function get_url_contents($url) {
        $crl = curl_init();

       curl_setopt($crl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
        curl_setopt($crl, CURLOPT_URL, $url);
        curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($crl, CURLOPT_SSLVERSION,3);
        curl_setopt($crl, CURLOPT_SSL_VERIFYPEER, true);

        $ret = curl_exec($crl);
        curl_close($crl);
        return $ret;
    }

    $width=260;$height=229;
    $a=0;
    foreach($Query_Gift as $two):
    $a++;
    $amazon = new AmazonProductAPI('xxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxx', 'xx','xx');

           $similar = array(
            'Operation' => 'BrowseNodeLookup',
            'BrowseNodeId' => $two->gift_interest_value
          );

        $result = $amazon->queryAmazon($similar);
        $result = json_decode(json_encode($result));
        $b=0;

    $json = get_url_contents('http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q="'.str_replace(' ','',$two->gift_interest_name).'"');
    $data = json_decode($json);


    foreach ($data->responseData->results as $result_1) {

        $results[] =$result_1->url;             
    }

    $c=$a * 4;



    foreach ($result->BrowseNodes->BrowseNode->Children->BrowseNode as $one){
            $b++;

                $Id_Node=$one->BrowseNodeId;

                if($b==1){
                $name=$results[($c-4)];
                }
                else{
                    $name=$results[($c-2)];
                    $b=0;
                }
                    $filename   = pathinfo($name, PATHINFO_FILENAME).'_'.$one->BrowseNodeId;
                    $ext        = pathinfo($name, PATHINFO_EXTENSION);
                    $newName        =preg_replace( "/[^a-zA-Z0-9\._]+/", "-", strtolower($filename) ).'.'.$ext;

                    $ImgSave='my/path/' .$newName;
                    file_put_contents($ImgSave, file_get_contents($name));
                 $re200='/my/another_path/' .$newName;
                     $file_2=$ImgSave; 
                     $image_2=Yii::$app->image->load($file_2);
                     $Img_2= $image_2->resize($width,$height, 'NONE')->render();
                     $image_2->save($re200, 100);

                    $Img='assets2/images/category/' .$newName;
        }
        endforeach;
   ?>

最佳答案

curl_setopt($crl, CURLOPT_SSLVERSION,3);

不要那样做。 SSLv3 已被弃用,大多数 Web 服务器(包括 Google)不再支持。

关于php - 文件获取内容(): Failed to enable crypto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33449549/

相关文章:

php - Yii2: Jui Auto Complete Widget 如何实现?

php - acos(1) 在某些情况下返回 NAN

php - 如何使用id显示数据库中的名称?

php - Max Unix timestamp 在 php 中搜索 spesifit 时间

php - 如何从 Ubuntu CLI 运行 Yii 控制台应用程序?

javascript - 如何在javascript中读取php对象关系(自定义属性)

javascript - 如何获取选中的gridview列的值

php - Yii2:从提交按钮重定向到特定操作

php - Yii:STAT 与条件的关系

php - 如何使用 Laravel 在控制台图表中传递值