0

I am using mPDF library to generate a pdf from my php server script. I have used composer to install the library into my live server file system.

I was being able to generate the pdf file successfully for quite a couple of months, until today morning. Everytime I try to generate the pdf it shows this error in the console:

Notice: file_get_contents(): Read of 8192 bytes failed with errno=21 Is a directory in /home/user/domains/report_generation/backend_pdfgen/vendor/mpdf/mpdf/src/File/LocalContentLoader.php on line 10

According to the console, I went to line 10 in LocalContentLoader.php. This is the code:

<?php

namespace Mpdf\File;

class LocalContentLoader implements \Mpdf\File\LocalContentLoaderInterface
{

    public function load($path)
    {
        return file_get_contents($path);
    }

}

This is my pdf generation script (pdfgen.php):

<?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);

    require_once __DIR__ . '/vendor/autoload.php';

    $mpdf = new \Mpdf\Mpdf(['setAutoTopMargin' => 'stretch']);
    $mpdf->SetTitle("report.pdf");
    $mpdf->SetAuthor("Anonymous");
    $mpdf->WriteHTML('<div style="text-align:center";>Some data here</div>');
    $mpdf->Output("reports/report.pdf");
?>

My file hierarchy:

enter image description here

I am not being able to understand what's wrong with it. I surfed on the internet and found a post where it was mentioned that I have to increase the upload_max_filesize, it's already increased to 1 GB, but still the error message shows. Where am I going wrong. Please guide me.

Surprisingly, the error doesn't show when I run the script in my localhost server.

Nico Haase
  • 11,420
  • 35
  • 43
  • 69
  • No, but I think it's because of **insufficient disk space**, because when I run the server script in my **localhost** server, then it works!! –  Jan 29 '23 at 05:56
  • Does this answer your question? [Error file\_get\_contents(): read of 8192 bytes failed with errno=21](https://stackoverflow.com/questions/62542374/error-file-get-contents-read-of-8192-bytes-failed-with-errno-21) – user1844933 Jan 29 '23 at 16:37

1 Answers1

0

This is very likeley because of insufficient disk space.

Try another location or verify you have enough space. Check where report.pdf is intended to be safed.

Jonathan
  • 1,955
  • 5
  • 30
  • 50