【问题标题】:Laravel list of file names from ZIP archive, show in blade来自 ZIP 存档的 Laravel 文件名列表,显示在刀片​​中
【发布时间】:2021-02-11 01:23:23
【问题描述】:

在刀片中显示 ZIP 存档中包含的文件的名称时我很容易。

blade controller:

$zip_archive = new \ZipArchive(); 

    $zip_archive->open($fileName); 
    
    for( $i = 0; $i < $zip_archive->numFiles; $i++ ){ 
        $stat = $zip_archive->statIndex( $i ); 
        print_r( basename( $stat['name'] ) . PHP_EOL ); 
    }

print_rblade 1.png 2.png 中显示。 3.png 4.png

可以将其转换为表格吗?

类似

@foreach ($ as $)
    <td>{{ }}</td>
@endforeach

【问题讨论】:

    标签: php laravel foreach laravel-blade ziparchive


    【解决方案1】:

    在你的方法中

        $zip_archive = new \ZipArchive(); 
        $zip_archive->open($fileName); 
        $filenames= [];
        if(!empty($zip_archive)){
           for($i = 0; $i < $zip_archive->numFiles; $i++ ){ 
                $stat = $zip_archive->statIndex( $i ); 
                // file's name
                $filenames[] = "{construct it}"; 
          }
        }
        return view('your_view',["filenames"=>$filenames]);
    

    在你看来

      @if(count($filenames) > 0) 
         @foreach($filenames as $filename)
           {{$filename}}
         @endforeach
       @endif 
    

    【讨论】:

    • dd($filenames) 完美显示所有文件名的数组。但是刀片 ERROR: undefined variable:filenames in your_view.blade.php 中可能有什么问题?
    • 通过此更改您的解决方案工作 -> 将此 return view('your_view', $filenames); 更改为 return view('your_view',["filenames"=&gt;$filenames]);
    猜你喜欢
    • 1970-01-01
    • 2020-02-03
    • 1970-01-01
    • 2016-06-14
    • 2020-03-18
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多