简体   繁体   中英

Laravel 5 DOMPDF imagepng(.png): failed to open stream: Permission denied

I am using DOMPDF to generate pdf.

Here is my pdf.blade.php:

<img src="{{ public_path() . '/images/logo.png' }}" id="logo" />
<table class="order_confirmation"> 
    <tbody>
        <tr>
            <th>Company name</th>
            <td>Name</td>
        </tr>
        <tr>
            <th>Email</th>
            <td>test@email.com</td>
        </tr>
    </tbody>
</table>

Here is my controller method:

public function pdf() {
    $data = array();
    $pdf = PDF::loadView('pdf', $data);
    return $pdf->stream();
}

Here is error:

ErrorException in class.pdf.php line 4036: imagepng(.png): failed to open stream: Permission denied

And a stacktrace:

in class.pdf.php line 4036 at HandleExceptions->handleError('2', 'imagepng(.png): failed to open stream: Permission denied', '/Applications/XAMPP/xamppfiles/htdocs/blablacompany/vendor/dompdf/dompdf/lib/class.pdf.php', '4036', array('file' => '/Applications/XAMPP/xamppfiles/htdocs/blablacompany/public/images/logo.png', 'x' => '34.015748031496', 'y' => '606.8742519685', 'w' => '334.5', 'h' => '201', 'byte' => '6', 'img' => 'Resource id #278', 'eight_bit' => false, 'wpx' => '446', 'hpx' => '268', 'tempfile_alpha' => '.png', 'tempfile_plain' => '.png', 'imgalpha' => resource, 'c' => '256', 'allocated_colors' => array('000' => '0', '9598261', '12756008', '9993266', '15848487', '7493443', '12690472', '16309032', '14269479', '5586004', '11637804', '16243240', '8809018', '2169210', '12624680', '15256615', '6638155', '2366072', '5454677', '10256177', '13151271'...

Could you please help me?

PS

  1. I have tried also url('/images/logo.png') instead of public_path() . '/images/logo.png'
  2. I have chmod 777 on storage, vendors and also on public/images, but still not working...

ErrorException in image_cache.cls.php line 105: file_put_contents(): Filename cannot be empty

UPDATE:

  • if I set chmod 754 and return view('pdf') -> image is not shown (as well as on other pages which are using images/
  • if I set chmod 754 and $pdf = PDF::loadView('pdf', $data); return $pdf->stream(); $pdf = PDF::loadView('pdf', $data); return $pdf->stream(); -> PDF is generated but image is stroked square
  • but if I set chmod 755 and return view('pdf') -> images is shown, but..
  • when I try $pdf = PDF::loadView('pdf', $data); return $pdf->stream(); $pdf = PDF::loadView('pdf', $data); return $pdf->stream(); I receive an error message:

ErrorException in image_cache.cls.php line 105: file_put_contents(): Filename cannot be empty

I figured out how to deal with it:

  1. for pdf generation you should use public_path() instead of url('') (eg <img src="{{ public_path() . '/images/somepicture.jpg' }}" id="logo" /> ),
  2. public_path() won't work if want to load view return view('yourview');

  3. Use only .jpg , .png won't work

  4. chmod 755 your image folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM