Collection.php 1.46 KB
<?php

namespace app\components;

use Yii;
use yii\base\Component;

class Collection extends Component
{
    //Скачиваине URL файла и передача пути к нему
    public static function download_file($csvFile)
    {
        $out = '';
        $temp_csv_name = tempnam(sys_get_temp_dir(), 'rkn_');
        if ($temp_csv_name !== false)
            {
                $file_handle = fopen((string)$csvFile, 'r');
                if ($file_handle!==false)
                    {
                        $file_write = file_put_contents($temp_csv_name, $file_handle);
                        if ($file_write!==false)
                            $out = $temp_csv_name;
                        unset($file_write);
                        fclose($file_handle);
                    }
                unset($file_handle);
            }
        unset($temp_csv_name);
        return $out;
    }


    public static function getRawData($url, $domain)
    {
        $post = [
            'a' => 'act',
            'ip' => $domain,
        ];
        $ch = curl_init('https://2ip.ua/ru/services/information-service/domain-information');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

        $response = curl_exec($ch);
        $errorNum = curl_errno($ch);
        $errorMsg = curl_error($ch);

        curl_close($ch);

        return ['data' => $response, 'errorno' => $errorNum, 'errormessage' => $errorMsg];
    }

}