Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Penaf's avatar
Level 1

file_get_contents(): Peer certificate CN

Having on my index view this line (that repeats for all icons):

{!! file_get_contents(asset('/assets/img/icons/chevron_down.svg')) !!}

I got into trouble when the file was not found and that generated this: [ommited machine IP address]

2019-05-23 15:12:24] local.ERROR: file_get_contents(): Peer certificate CN=`eco.***.pt' did not match expected CN=`193.*.*.*' (View: /var/www/clients/client3/web7/private/laravel/resources/views/layouts/default.blade.php) (View: /var/www/clients/client3/web7/private/laravel/resources/views/layouts/default.blade.php) {"exception":"[object] (ErrorException(code: 0): file_get_contents(): Peer certificate CN=`ecocampus.utad.pt' did not match expected CN=`193.*.*.*' (View: /var/www/clients/client3/web4/private/laravel/resources/views/layouts/default.blade.*) (View: /var/www/clients/client3/web4/private/laravel/resources/views/layouts/default.blade.php) at /var/www/clients/client3/web4/private/laravel/storage/framework/views/5202fd7b45c252baee2039b21032a54447b62494.php:106, ErrorException(code: 0): file_get_contents(): Peer certificate CN=`eco.***.pt' did not match expected CN=`193.*.*.*' (View: /var/www/clients/client3/web7/private/laravel/resources/views/layouts/default.blade.php) at /var/www/clients/client3/web4/private/laravel/storage/framework/views/5202fd7b45c252baee2039b21032a54447b62494.php:106, ErrorException(code: 0): file_get_contents(): Peer certificate CN=`eco.***.pt' did not match expected CN=`193.136.*.*' at /var/www/clients/client3/web4/private/laravel/storage/framework/views/5202fd7b45c252baee2039b21032a54447b62494.php:106)

The machine crashed with so many errors.

Is there anyway to avoid this kind of erros with the asset() function?

0 likes
6 replies
Snapey's avatar

Are you trying to inline svg files?

Why use asset? its going to produce a URL rather than just a path

Penaf's avatar
Level 1

So I should just use a path for the inline SVG? Thought the correct way as to use the asset() to generate the full url

The thing is that my laravel app is inside the folder 'private/laravel/' and the index.php is on the folder '/web'

When doing this in blade

{!! file_get_contents('assets/img/icons/chevron-down.svg') !!}

is it getting the file in the resources/assets/img/... or in the public/assets/img/...

I feel like I'm making a huge confusion here.

Snapey's avatar

if you are in-lining the svg then you just need to get its contents. It does not matter if it is internal or external since everything is running in php at this point.

Where are your svg files located?

Penaf's avatar
Level 1

In relation to laravel's index.php file on server public folder the svg files are on assets/img/icons/

Snapey's avatar

try

{!! file_get_contents(public_path('/assets/img/icons/chevron_down.svg')) !!}
jlrdw's avatar

If that don't work, I have used readfile with success

<?php
$basedir = '/your_path_here_to/laravel55up/storage/app/upload';
$imagedir = $_GET['dir'];
$image = $_GET['img'];

$file = $basedir.'/'.$imagedir.'/'.$image;
$fallback = $basedir.'/fallback.gif';
$size = filesize($file); // File size
$length = $size;
//DETERMINE TYPE
$ext = array_pop(explode ('.', $file)); // adjust as needed
$allowed['gif'] = 'image/gif';
$allowed['png'] = 'image/png';
$allowed['jpg'] = 'image/jpeg';
$allowed['jpeg'] = 'image/jpeg';

if(file_exists($file) && $ext != '' && isset($allowed[strToLower($ext)])) {
    $type = $allowed[strToLower($ext)];
} else {
    $file = $fallback;
    $type = 'image/gif';
}

header("Accept-Ranges: bytes");
header("Cache-Control: public");
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $length);
header("Content-Disposition: inline; filename=\"".$image."\";");
header("Last-Modified: " . date('r', filemtime($file)));

ob_clean();
readfile($file);
exit(0);

?> 

File called with an img src tag.

<img src="<?= '/laravel55/pthru.php?dir=imgdogs&img='  . $dog->dogpic; ?>" alt="" class="imgborder"></a>

Just convert to blade.

Please or to participate in this conversation.