file_get_contents(): 启用加密失败

5
当我尝试从Google获取图片时,对于单个搜索,它会提供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;
   ?>

https://dev59.com/g2Yq5IYBdhLWcg3w7E-w#14078318 - Mihai
可能是OPENSSL file_get_contents(): Failed to enable crypto的重复问题。 - Nico Haase
2个回答

1
curl_setopt($crl, CURLOPT_SSLVERSION,3);

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


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接