Skip to content
Advertisement

PHP I can’t show the button on the HTML page showing a PDF file

I have a language course consisting of a pdf and an mp3 file.
My goal is to show the pdf file in the browser, with a button that launches the audio file from VLC.
If I try the various parts individually (button or pdf) they work.
The button without pdf works. When I press it, it shows me the VLC mp3 file.
The Pdf file without button is correctly shown.
But when I put them together (button and pdf together), I only see the pdf file and I don’t see the button anymore.
I have the impression that the pdf hides the button.
I don’t know how to show the button together with the pdf.
Is there anything I can do?
Thank you. The code I use is this:

<HTML>
<BODY>
  <form method="post">

    <input type="submit" name="forward" value="forward">

<?php

  $name = 'C:UsersioDesktopVol_1.pdf';
  $content = file_get_contents($name);
  header('Content-Type: application/pdf');
  header('Content-disposition: inline; filename="' . $name . '"');
  echo $content;

  if ($_POST["forward"]??0) {
    system("vlc C:UsersioDesktopa.mp3");
  }

?>

  </form>

</BODY>
</HTML>

Advertisement

Answer

You can try this, Much simpler and without php or vlc:

  <audio controls>
   <source src="a.mp3" type="audio/mp3">
 Your browser does not support the audio element.
 </audio>

    <!-- <object  width="1024" height="900" type="application/pdf" data="Vol_1.pdf?&scrollbar=0&toolbar=0&navpanes=0" >
          <p>Insert your error message here, if the PDF cannot be displayed.</p>
      </object>  -->


<iframe src="Vol_1.pdf" style="width:1500px; height:800px;" frameborder="0" allowfullscreen="true"></iframe>

You can choose between object or iframe as you like. That way you have both pdf and mp3 on the page, and you don’t even have to reload the page when you click the button.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement