2013-08-16 4 views
0

내 문제는 다운로드 아이콘을 클릭하여 파일 (확장자)을 다운로드하는 것입니다. Print 문으로 시도했지만 새 창이 열리고 사용자가 표시됩니다 전체 웹 페이지를 인쇄 할 수 있지만 쿼리에서 하나의 파일을 다운로드하도록 지정해야합니다. 어떤 아이디어?웹 페이지에있는 mysql 결과에서 파일을 다운로드하십시오.

이 그것을 할 수 있어야 이미지에 사용자 클릭이

doc_id passport_no photo   nic_copy   passport_copy 
    200004 N8899999  1376630109.jpg 1376630110.jpg 1376630111.jpg 

을 다운로드 할 때 내 쿼리가 표시되는 방법이며,이 제는

<?php if (isset($_GET['file'])) { 
$file = $_GET['file']; 
if (file_exists($file) && is_readable($file) && preg_match('/\.pdf$/',$file)) { 
header('Content-Type: application/pdf'); 
header("Content-Disposition: attachment; filename=\"$file\""); 
readfile($file); 
} 
} else { 
header("HTTP/1.0 404 Not Found"); 
echo "<h1>Error 404: File Not Found: <br /><em>$file</em></h1>"; 
} 
?> 

.. 다운로드 링크

코딩한다
<a href="http://localhost/visa/view.php?file=example.pdf">Click here to download PDF</a> 
+0

이가 내 문제를 해결 도움이 당신이 –

답변

0
<a href="view.php?file=<?php echo $row['filename']; ?>">Click here to download PDF</a> 
this will be your view.php 
<?php 
$f="upload/".$_REQUEST['file']; // upload is your destination folder where you uploading you files 
if(file_exists($f)) 
{ 
header('Content-Description: File Transfer'); 
header('Content-Type: application/pdf'); 
header('Content-Disposition: attachment; filename='.basename($f)); 
header('Content-Transfer-Encoding: binary'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate'); 
header('Pragma: public'); 
header('Content-Length: ' . filesize($f)); 
ob_clean(); 
flush(); 
readfile($f); 
exit; 
?> 
+0

감사 @chirag 송시 시도 보여, 난 그냥 가장 사랑하는 :-)을 환영 내 코드 – YathuGulan

+0

에 변경 한 –

0

사용 PH P 헤더를 사용하여 파일을 표시하지 않고 브라우저에 저장하도록 지시합니다.

header('Content-disposition: attachment; filename=whatever.ext'); 
header('Content-type: mime/type'); 
//echo file contents out here 
관련 문제