php/mysql: Open file by name reference
Posted: Sat Sep 29, 2012 7:02 pm
Hi everyone,
in a mysql database, filenames are stored in a table like so: ODm0QCVFEsAOHriuFvfS.pdf[test.pdf]
each file represents the actual file name saved and in brackets the filename to display on the page.
my php script then lists all the filenames on a page and when a file is clicked on, it opens the file with a save as prompt with the actual filename (ODm0QCVFEsAOHriuFvfS.pdf). Is there a way to modify my code to display the filename in the [], for example test.pdf in the save as dialogue box?
thanks.
in a mysql database, filenames are stored in a table like so: ODm0QCVFEsAOHriuFvfS.pdf[test.pdf]
each file represents the actual file name saved and in brackets the filename to display on the page.
my php script then lists all the filenames on a page and when a file is clicked on, it opens the file with a save as prompt with the actual filename (ODm0QCVFEsAOHriuFvfS.pdf). Is there a way to modify my code to display the filename in the [], for example test.pdf in the save as dialogue box?
Code: Select all
<?php // $attachments = "ODm0QCVFEsAOHriuFvfS.pdf[test.pdf],XHprKsLP0J1EddvUGgpa.doc[test.doc]";
preg_match_all('/([^\[]+)\[([^\]]+)\],?/', $attachments, $matches, PREG_SET_ORDER);
$attachments = array();
foreach ($matches as $file) {
$attachments[$file[1]] = $file[2];
}
foreach ($attachments as $file => $filename) {
echo '- <a href="mail/attachments/' . htmlspecialchars($file, ENT_QUOTES) . '"target="_new" name="' . htmlspecialchars($filename, ENT_QUOTES) . '">' . htmlspecialchars($filename, ENT_QUOTES) . '</a><br />' . PHP_EOL;
} ?>