A8C_Files::check_to_download_file PHP Метод

check_to_download_file() публичный Метод

Ensures a local copy of the imported xml file is available for local reading at the final import step
    function check_to_download_file()
    {
        $step = empty($_GET['step']) ? 0 : (int) $_GET['step'];
        if (2 !== $step) {
            return;
        }
        $this->id = (int) $_POST['import_id'];
        $file = get_attached_file($this->id);
        if (!$file || file_exists($file)) {
            return;
        }
        $service_url = $this->get_files_service_hostname() . '/' . $this->get_upload_path();
        if (is_multisite() && !(is_main_network() && is_main_site())) {
            $service_url .= '/sites/' . get_current_blog_id();
        }
        $file_url = str_ireplace(constant('LOCAL_UPLOADS'), $service_url, $file);
        $opts = array('http' => array('method' => "GET", 'header' => 'X-Client-Site-ID: ' . FILES_CLIENT_SITE_ID . "\r\n"));
        $context = stream_context_create($opts);
        $file_data = file_get_contents($file_url, false, $context);
        if ($file_data) {
            $directory = pathinfo($file)['dirname'];
            if (!file_exists($directory)) {
                mkdir($directory, 0777, true);
            }
            file_put_contents($file, $file_data);
            register_shutdown_function('unlink', $file);
        }
    }