John Davidson

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

0 comments
Message:


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


edit:


// If absolute URL from the remote server is provided, configure the CORS
// header on that server.
var url = 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf';

// 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 = '//mozilla.github.io/pdf.js/build/pdf.worker.js';

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


My Answer:
"example.com/default.pdf"
},
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

Comments




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