php - Download document from sqlite through website -
i have store sample document inside local server named template.doc. store file directory inside sqlite table. manage call out path of file directory how can allow user download it?
codes
<form id="list" name="list" method="post" action=""> <select name="list" id="list"> <?php if ($choice !="no") { $path = $_server['document_root']."/web/"; $fullpath = $path.$_get['$choice']; echo "<form id=\"form7\" name=\"form7\" method=\"post\" action=\"\">"; echo "<input type=\"submit\" name=\"download\" id=\"download\" value=".$fullpath."/>"; if (file_exists($fullpath)) { header('content-description: file transfer'); header('content-type: application/octet-stream'); header('content-disposition: attachment; filename='.basename($fullpath)); header('content-transfer-encoding: binary'); header('expires: 0'); header('cache-control: must-revalidate'); header('pragma: public'); header('content-length: ' . filesize($fullpath)); ob_clean(); flush(); readfile($fullpath); echo "<label>".$fullpath."</label>"; echo "<input type=\"submit\" name=\"download\" id=\"download\" value=".$fullpath."/>"; exit; echo '</form>'; } } ?>
how create button below list form , download microsoft word? flushes out microsoft word text on website now, not on button. kindly advise if it's possible it. local testing. alot!
you can use readfile
, set appropriate headers force download.
example readfile domestication page:
<?php $file = 'monkey.gif'; if (file_exists($file)) { header('content-description: file transfer'); header('content-type: application/octet-stream'); header('content-disposition: attachment; filename='.basename($file)); header('content-transfer-encoding: binary'); header('expires: 0'); header('cache-control: must-revalidate'); header('pragma: public'); header('content-length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; } ?>
your form should this
<form name="download" action="download.php" method="post"> <input type="hidden" name="fileid" value="some file identifier" /> <input type="submit" name="submit" value="download file" /> </form>
then, in download.php
if(isset($_post["submit"])) { $file = $_post['fileid']; // download file }
Comments
Post a Comment