I’m really new to PHP but what I want to do is make a dynamic table of contents for some of my companies job offerings.
So if i put all the pdfs of the job descriptions in a folder called ../jobops with the php file located in root directory what would I need to do.
Should work. Takes the directory, scans it, maps all the filenames into an array
$contentsremoves the relative urls (the “.” and “..”) and then echoes them out.Remember that
foreachis relatively expensive, though; so you may wish to simply unset$contents[0]and$contents[1].Edited in response to the following (from the OP):
The
$directoryvariable is relative to where the script is being called. In my case, this runs from the root folder so it should be, for me,$directory = "jobops"assuming the folder and script are stored in the same place. Without knowing your server’s directory structure I can’t really help you, but I would suggest ruling out a problem with thescandir()function.To do this, create a folder in the same directory as your script called whatever you like, populate it with at least one image (so that the following
if()doesn’t unset the entire array) and see if that works. If it does then you’re stuck with finding the relative path to your folder. If it doesn’t then I’m stuck myself.