Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your PDF data is stored in the database in BLOB fields, I don't see you putting this data in a file. So your ZIP will not contain any files because you don't add real existing files to it.</p> <p>This is what you are currently doing:</p> <ul> <li>Reading your data from the database</li> <li>Creating an array of filenames</li> <li>Creating a ZIP of filenames that might not exist</li> </ul> <p>This what you should do:</p> <ul> <li>Reading your data from the database</li> <li>Creating an array of filenames</li> <li>Write your BLOB data into that files</li> <li>Creating a ZIP of files that exist</li> </ul> <p>Example:</p> <pre><code> $files = array(); while(list($username, $description, $type, $size, $content) = mysql_fetch_array($result)) { $files[] = "$username-$description.pdf"; // write the BLOB Content to the file if ( file_put_contents("$username-$description.pdf", $content) === FALSE ) { echo "Could not write PDF File"; } } </code></pre> <p>What you should do if that works for you:</p> <p>Write the files in a temporary folder (maybe with some help of <a href="http://php.net/tempnam" rel="nofollow noreferrer">http://php.net/tempnam</a>) somewhere else and maybe remove them after your archiving process.</p> <p>There is also a second problem in your code, you use $zipfilename for calculating the content-length and $zipname to read the file and no variable to create the zip. Since $zipfilename and $zipname is not defined, this won't work.</p> <p>You should define $zipfilename with a ZIP filename and also use that same variable when creating the zip file.</p> <p>Example:</p> <pre><code> // a temp filename containing the current unix timestamp $zipfilename = 'temp_' . time() . '.zip'; $zip-&gt;open($zipfilename, ZipArchive::CREATE); foreach ($files as $file) { $zip-&gt;addFile($file); } $zip-&gt;close(); header('Content-Type: application/zip'); header('Content-disposition: attachment; filename=filename.zip'); header('Content-Length: ' . filesize($zipfilename)); readfile($zipfilename); </code></pre>
 

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