dompdf 图像未显示在blade 文件 laravel 中

问题描述 投票:0回答:3

我不断收到此错误,

Maximum execution time of 60 seconds exceeded
,每当我尝试下载 pdf 时,我环顾四周,大多数人都说更改 php.ini max_execution time。我已经这样做了,但仍然收到错误。我在文件夹 xampp/php.ini 中更改了它,不确定它是否正确。我尝试在我的 laravel 项目下查找 php.ini 但那里没有这样的文件。我尝试的另一件事是将
ini_set('max_execution_time', 60);
放在blade.php 的顶部,但仍然不起作用。谁能帮我?预先感谢

测试.blade.php

<?php ini_set('max_execution_time', 60); ?>
<div class="container">
@foreach($object as $test)
@if( $pdf == 0 )
  <a href="{{url('/pdfview')}}{{$test->id}}">Download PDF</a>
  @endif
@endforeach
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
    border: 2px solid black;
    width: 60%;
}
</style>
</head>
<body>
<table align="center">
  <tr>
    <th>Designation</th>
    <th>
      @foreach($data3 as $currentUser)
      <img src="{{ url('images/' . $currentUser->name ) }}">
      @endforeach
    </th>
  </tr>
 </table>
</body>
</html>
</div>

pdfDownloadController.php(下载pdf时会出现未定义的错误,所以这样做了)

   public function pdfview($id)
    {

        $object = personal_info::where('id',$id)->get();
        $object1 = additional_info::where('user_id',$id)->get(); 
         $data3=UserImage::where('user_id',$id)->get();
         $object4 = language::where('user_id',$id)->get();

        $pdf = PDF::loadView('test', compact('id','object','object1','data3','object4'), array('pdf' => true));
        return $pdf->download('test.pdf');
          return view('test', array('pdf' => false));
    }

testController: //显示在test.blade.php中

     public function getBiodata($id){

          $object = personal_info::where('id',$id)->get();

        $object1 = additional_info::where('user_id',$id)->get(); 
         $data3=UserImage::where('user_id',$id)->get();
         $object4 = language::where('user_id',$id)->get();
          $pdf = PDF::loadView('biodata', compact('id','object','object1','data3','object4'), array('pdf' => 1));

     return view('biodata',compact('id','object','object1','data3','object4'),array('pdf' => 0 ));

 }
php image laravel laravel-5
3个回答
4
投票

正如我所做的那样,我的项目之一:- 改变了这个:-

<img src="{{ url('images/' . $currentUser->name ) }}">

致:-

<img src="./images/{{$currentUser->name}} />

希望有帮助!


1
投票

以下代码运行良好:

名称)}}"> 或姓名)}}">

0
投票

2024 年,如果有人遇到类似问题并正在寻找解决方案,请确保您的图像采用 Base64 编码,并根据您的图像所在位置使用

base_path()
storage_path()
提供绝对路径。对于上面的情况,它看起来像这样:

<img src="data:image/png;base64,<?php echo base64_encode(file_get_contents(base_path('public/images/'.$currentUser->name))); ?>" />

我希望这对某人有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.