Shiva Tiwari

Shiva Tiwari

  • NA
  • 73
  • 4.7k

Message is not displaying after downloading the file

Jun 3 2020 2:27 AM
  1. $msg=DisplayMsg();  
  2. if($msg)  
  3. {  
  4. try  
  5. {  
  6. $select = "SELECT * FROM `success-stories` where id='$id'";  
  7. $result = $conn->query($select);  
  8. $row = $result->fetch_assoc();  
  9. $file=$row["download_pdf"];  
  10. $file_arr=explode("/",$file);  
  11. $path=$file_arr[0]."/".$file_arr[1]."/".$file_arr[2];  
  12. if(file_exists($path))  
  13. {  
  14. header('Content-Description: File Transfer');  
  15. header('Content-Type: application/pdf');  
  16. header('Content-Disposition: attachment; filename="'.$path.'"');  
  17. header('Expires: 0');  
  18. header('Cache-Control: must-revalidate');  
  19. header('Pragma: public');  
  20. header('Content-Length: ' . filesize($path));  
  21. ob_clean();  
  22. ob_flush();  
  23. readfile($path);  
  24. }  
  25. }  
  26. catch(Exception $e) {  
  27. echo 'Caught exception: ', $e->getMessage(), "\n";  
  28. }  
  29. }  
  1. <?php  
  2. function DisplayMsg()  
  3. {  
  4. $val="";  
  5. try{  
  6. echo "<h4 class='alert alert-success'>Thank you for downloading story</h4>";  
  7. }  
  8. catch(Exception $e)  
  9. {  
  10.   
  11. }  
  12. return $val="success";  
  13. }  
  14. ?>  

Answers (1)