mardi 7 août 2018

Error: get_headers(): php_network_getaddresses: getaddrinfo failed: No such host is known

I am trying to run this code:

    public function show(Request $request, $id)
{
    $material   = Material::with('tags')->where(
        'uuid',
        $id
    )->first();

    if (isset($material)) {

        $material_media   = $material->getMedia();

        $material->file_path    = $material_media->first(function ($value) {
            return $value->collection_name === 'materials/files';
        })->getUrl(); 

        $material->preview_image_path   = $material_media->first(function ($value) {
            return $value->collection_name === 'materials/previews';
        });

        if (isset($material->preview_image_path)) {
            $material->preview_image_path   = $material->preview_image_path->getUrl();
        }

        $headers    = get_headers($material->file_path);

        // Extract content type from response header
        foreach ($headers as $header) {
            if (preg_match('/^Content-Type:(.+)/', 'Content-Type: application/pdf', $matches) > 0) {
                $material->content_type = trim($matches[1]);
            }
        }


        unset($material->media);

    }

    return response()->json(compact('material'));
}

and I get the error:

"get_headers(): php_network_getaddresses: getaddrinfo failed: No such host is known. "

$material->file_path returns the url of the file from s3.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire