0

I have a html file that has to be converted into pdf. My code is:

<?php
include("connection.php");
extract($_REQUEST);

$query=mysql_query("select fad_html_name from fad_record where t_id='$word'") or die(mysql_error());
while($result=mysql_fetch_array($query,MYSQL_NUM))
{
extract($result);

$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($result as $file) {
 $zip->addFile($file);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);

}
?>

This isn't working.zip file is being created, but pdf doesn't get downloaded.

user3526766
  • 93
  • 1
  • 3
  • 16
  • 1
    FYI, [you shouldn't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](https://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which one is best for you. – John Conde Jul 26 '17 at 14:00
  • 1
    Your code does not convert anything to a pdf, nor does it add anything to the zip. The Zip remains empty as `addFile` probably expects a file pointer whereas you pass it an array. – coderodour Jul 26 '17 at 17:59
  • Get https://wkhtmltopdf.org/ – Chris O Jul 26 '17 at 21:30

0 Answers0