0

From Ziparchive want name and size of files in Zip file. Problem for me is how can add name and size to table in blade view.

controller:

    $ziparchive = new \ZipArchive(); 
    $ziparchive->open($fileName);
    $filenames = [];
    $filesizes = [];
    if(!empty($ziparchive)){         
        for( $i = 0; $i < $ziparchive->numFiles; $i++ ){ 
            $stat = $ziparchive->statIndex( $i ); 
            $filenames[]= basename( $stat['name'] ) . PHP_EOL;
            $filesizes[]= basename( $stat['size'] );

    return view('view',["filenames"=>$filenames,"filesizes"=>$filesizes]);

dd($filenames, $filesizes) return two arrays:

 1.png
 2.png
 3.png
 4.png

 10
 12
 13
 796

in view.blade.php

@foreach($filenames as $filename )
    @foreach($filesizes as $filesize)
        <tr>
            <td>{{$filename}}</td>
            <td>{{$filesize}}</td>
        </tr>
    @endforeach
@endforeach

return in table this:

 1.png 10
 1.png 12
 1.png 13
 1.png 796
 2.png 10
 2.png 12
 2.png 13
 ....

what do i missing ?

1 Answer 1

1

try this

@foreach($filenames as $key => $filename )
    <tr>
        <td>{{ $filename }}</td>
        <td>{{ $filesizes[$key] ?? "" }}</td>
    </tr>
@endforeach

as both $filenames and $filesizes same index have same value so you can use index to get value from $filesizes[index]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.