John Davidson

javascript - Detect/find *.pdf on server (with php?) and pass it to .js file


I'm completely new to javascript. I have a .js (running on webserver) file with two options:

defaultUrl: {
value: "filename.pdf",
kind: OptionKind.VIEWER

and instead of filaname.pdf name I would like it to detect any .pdf file in current working folder (there will always be one, but each time with different filename) and return it's name here

The file is on shared web hosting - so I probably can run some .php code to find the filename


// If absolute URL from the remote server is provided, configure the CORS
// header on that server.
var url = '';

// Loaded via <script> tag, create shortcut to access PDF.js exports.
var pdfjsLib = window['pdfjs-dist/build/pdf'];

// The workerSrc property shall be specified.
pdfjsLib.GlobalWorkerOptions.workerSrc = '//';

// Asynchronous download of PDF
var loadingTask = pdfjsLib.getDocument(url);
loadingTask.promise.then(function(pdf) {
console.log('PDF loaded');

My Answer:
customUrl: {
value: ""

I want to add a function that will detect if a PDF file exists on the server and pass the URL to the customUrl option in the .js file. Is this possible with PHP? How can I achieve this?

Rate this post

3 of 5 based on 9937 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us