Note that there are some explanatory texts on larger screens.

plurals
  1. POwhen opened with winrar, Zip file obtained through Cakephp MediaViews reports Unexpected end of archive
    primarykey
    data
    text
    <p>What i am trying to achieve: Force download a zip file that contains user opted pdf files.</p> <p>What i did in controller to achieve this:</p> <ol> <li><p>Generate pdf reports in folder APP.WEBROOT_DIR.DS."package_files" (i used MPDF library) *it generates correct readable pdf. I call here $this->render();</p></li> <li><p>With Zip feature of php, Generate package.zip (which consists pdf files from above specified folder) *it generates correct zip file, when downloaded from server it opens as valid zip file in windows.</p></li> <li><p>Set the controller viewClass to Media and set parameters to force download as zip file, *Again here I call here $this->render(); Issue: When i run i get zip file but when opened with winrar, Zip file obtained reports Unexpected end of archive.</p></li> </ol> <p>I am not getting any usefull articles to get through this issue...</p> <p><strong>What i guess is calling two times render is making file corrupt</strong> Thanks</p> <p>My controller code:</p> <p><code> /** before this code i generate pdf files and have no issue **/</p> <p>/** now scan through the directory and add all the pdf files to a zip archive **/</p> <pre><code> $dir = new Folder("".APP.WEBROOT_DIR.DS."package_files"); $files = $dir-&gt;find('.*\.pdf'); $zip = new ZipArchive(); foreach ($files as $file) { $file_path = $dir-&gt;pwd() . DS . $file; $filename = $dir-&gt;pwd() . DS ."package.zip"; if ($zip-&gt;open($filename, ZIPARCHIVE::CREATE)!==TRUE) { exit("cannot open &lt;$filename&gt;\n"); } $zip-&gt;addFile($file_path,$file); } $zip-&gt;close(); </code></pre> <p>/** now render the action to download the generated zip file **/</p> <pre><code> $this-&gt;viewClass = 'Media'; $params = array( 'id' =&gt; 'package.zip', 'name' =&gt; 'packaged_file', 'download' =&gt; true, 'extension' =&gt; 'zip', 'path' =&gt; APP . WEBROOT_DIR.DS.'package_files' . DS ); $this-&gt;set($params); $this-&gt;render(); </code></pre> <p></code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload