I have this piece of code to redirect the page to a pdf file. However, sometimes it shows all weird characters instead of the pdf file but sometimes it loads correctly. Why is that and how to fix? Thanks. :o

<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="1; URL=<?php echo $pdf_file;?>">
</head>
<h1>Opening</h1>
<center>Please wait...</center></BODY></HTML>

    Have you tried it on different computers or through different browsers....looks ok to me but you might also try using Location๐Ÿ™"$pdf_file)....not sure if that is the right syntax but check it out....

      At the top of the page, try doing something like this:

      <?php
        header("Location: http://blah.com/path/to/your.pdf"); 
        exit;
      ?>
      

      This may or may not fix your problem, but I highly recommend it over using meta refresh tags.

      If this still causes you problems, my next recommendation would be to have your PHP file create headers for the PDF content type and then passing the file through to the user.

      I'm not sure of the content type needed for PDF files, but you would use this at the top of the page before echoing the PDF file to the user, but this code is for jpegs... you need to replace it with the proper content type:

      <?php
        header("Content-type: image/jpeg");
      ?>
      

      Goodluck.

        Hey, perhaps I can help the community for once!

        browsers need to know which application to use to deal with the pdf. they need headers like

        header( "Content-Disposition: filename=<?php echo $pdf_file;?>");
        header( "Content-type: application/pdf");

        That should help. It's what Lusid said. The Content-type is application/pdf

        Ras.

          ๐Ÿ˜• Thanks but none of these seem working... and I have already upgraded everything. I am using IE 6.0/Acrobat Reader 6.0. I have tried using different OS and machine as well. Instead of showing the pdf, I have something like this sometimes:

          0000200880 00000 n 0000129337 00000 n 0000203189 00000 n 0000202189 00000 n 0000003748 00000 n 0000007417 00000 n 0000202273 00000 n 0000007535 00000 n 0000009198 00000 n 0000038708 00000 n 0000202357 00000 n 0000009351 00000 n 0000013272 00000 n 0000202441 00000 n 0000013390 00000 n 0000016697 00000 n 0000201323 00000 n 0000202525 00000 n 0000016826 00000 n 0000019935 00000 n 0000202609 00000 n 0000020075 00000 n 0000023917 ...

          This is only part of it... Ah... so sick of it. Any more help is appreciated.

            Write a Reply...