Intersysop2 Posted February 14, 2023 Share Posted February 14, 2023 Hello i am trying to embed a collection of pdf in a in a web page, i got the name to work but when i click on it, i get a Blank square, does anyone see anything wrong with my code ? Thanks ! $dir = "C:\inetpub\wwwroot\Docs\Manuals\Honda"; // Change this to the directory containing the PDF files $files = scandir($dir); foreach ($files as $file) { if (substr($file, -4) == ".pdf") { $filename = substr($file, 0, -4); echo "<button class=\"collapsible\">$filename</button>"; echo "<div class=\"content\">"; echo "<embed src=\"$dir/$file\" width=\"100%\" height=\"500\">"; echo "</div>"; } } ?> <script> var coll = document.getElementsByClassName("collapsible"); var i; for (i = 0; i < coll.length; i++) { coll.addEventListener("click", function() { this.classList.toggle("active"); var content = this.nextElementSibling; if (content.style.display === "block") { content.style.display = "none"; } else { content.style.display = "block"; } }); } </script> Quote Link to comment https://forums.phpfreaks.com/topic/315914-pdf-file-search-and-embed/ Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 This line: $filename = substr($file, 0, -4); is not doing what I think you want. Given file1.pdf that substr using 0,-4 will give you just file1 Are you trying to let the user select from a list of files (in the buttons) and have your script call another "display script" to put it on the screen for the user? Or is that js code supposed to do something to the current page? Quote Link to comment https://forums.phpfreaks.com/topic/315914-pdf-file-search-and-embed/#findComment-1605675 Share on other sites More sharing options...
requinix Posted February 14, 2023 Share Posted February 14, 2023 You can't embed files through C:\ if you're running this from a website. The "dir" that you use for the embed has to be a URL. Probably "/Docs/Manual/Honda". No, you can't also use that with scandir. Quote Link to comment https://forums.phpfreaks.com/topic/315914-pdf-file-search-and-embed/#findComment-1605677 Share on other sites More sharing options...
Intersysop2 Posted February 14, 2023 Author Share Posted February 14, 2023 is suppose to do some thing in current page, the $filename = substr($file, 0, -4); is just subtracting the .pdf extension from the name so i can use it for the button title Quote Link to comment https://forums.phpfreaks.com/topic/315914-pdf-file-search-and-embed/#findComment-1605678 Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 (edited) So that function that simulates an Ajax call - does it already work for you somewhere else? Do you know in fact that the event handler is being called? Add an alert to it perhaps to test it out? Of course this is after you get all the pdfs uploaded. Edited February 14, 2023 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315914-pdf-file-search-and-embed/#findComment-1605679 Share on other sites More sharing options...
Intersysop2 Posted February 14, 2023 Author Share Posted February 14, 2023 23 minutes ago, requinix said: You can't embed files through C:\ if you're running this from a website. The "dir" that you use for the embed has to be a URL. Probably "/Docs/Manual/Honda". No, you can't also use that with scandir. Can i amend or convert the string to a web address ? Quote Link to comment https://forums.phpfreaks.com/topic/315914-pdf-file-search-and-embed/#findComment-1605682 Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 Do you have a domain? Then of course you can. Create a sub-folder of your web root name and use that. Use $_SERVER['DOCUMENT_ROOT'] appended to the front of your files folder with a slash to join them. Quote Link to comment https://forums.phpfreaks.com/topic/315914-pdf-file-search-and-embed/#findComment-1605683 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.