PHP dynamically generating a download link list for a folder...

michaelsanford

Translator, Web Developer
PHP:
	$i = shell_exec("ls -1 ./mus_library/scarlatti/");
$i = str_replace("\n", "<br />", $i);
echo $i;

I have about 300 files I want to link to on my site, each has an associated PDF and MIDI (the score and the MIDI representation).

I obviously don't want to manually link all the files, so I'm using the above code to print a directory listing.

How can I work it so I get line items like this:
(filename without extension) | Download PDF | Download MIDI
?

BTW Dominico Scarlatti's pieces are identified by the K catalogue (like the M-Messier or NGC-New Galactic Catalogue numbers) so identifing the pieces by filename is acceptable...

I was thinking of filling an array like $files[] with each line item, but I don't know how to split the $i output so that the entire value of $i isn't put in $file(1)...

Any other suggestions are welcome.
 
well, for one thing, you could use PHP's built in functions to read a directory listing, but either way.Just list ONE file type. doesnt matter which, so long as each score has both a pdf and a midi. Rather than replacing a new line with a break, use explode() and set "\n" as the character string to split on. This will give you an array, one line in each entry. then just trim the extension, and use the new text to print the output, adding a ".pdf" and ".midi" where needed.
 
Back
Top