@Oleg06: no problem :-)
@mvlcek: - a semicolon is needed on the end of that command in the if statement (just a heads up for anyone who copy-pastes the code).
@GPB61: I've modified the code to deal with your two requests.
How to use:
- Set $detailsdir to the corresponding uploads folder of your product items.
- In $extensions, include the file types that you want to be displayed (e.g. if you want to show only .pdfs and .docs, ensure that they are in the array and no other extensions).
- If you only have one file for that particular item, then just upload it to the $detailsdir directory and it will be displayed as per mvlcek's version.
- If you want to have more than one file shown item, simply create a sub folder with that item's (well, the slug's) name and upload them there. All entries will be shown (showing n files as "Details: (1) (2) ....(n)").
This will allow you to have any number of files shown per item and no longer need to worry about naming conventions (if you simply put those files in the correct subfolder).
@mvlcek: - a semicolon is needed on the end of that command in the if statement (just a heads up for anyone who copy-pastes the code).
@GPB61: I've modified the code to deal with your two requests.
Code:
<?php
global $SITEURL;
$detailsdir = 'products/'; // modify to your file directory
$extensions = array('jpg', 'jpeg', 'gif', 'pdf'); // modify to include only desired file types
$item = return_page_slug(); // done to prevent calling the function repeatedly
foreach ($extensions as $extension) {
if(file_exists(GSDATAUPLOADPATH.$detailsdir.$item.'.'.$extension)) {
echo '<a href="'.htmlspecialchars($SITEURL.'data/uploads/'.$detailsdir.$item.'.'.$extension).'">Details</a> ';
}
}
if(file_exists(GSDATAUPLOADPATH.$detailsdir.$item.'/')) {
echo 'Details: ';
foreach(glob(GSDATAUPLOADPATH.$detailsdir.$item.'/*') as $key=>$filename) {
$file = end(explode('/', $filename));
$fileExt = strtolower(end(explode('.', $file))); // makes extension match case-insensitive
if(in_array($fileExt, $extensions)) echo '<a href="'.htmlspecialchars($SITEURL.'data/uploads/'.$detailsdir.$item.'/'.$file).'">('.($key+1).')</a> ';
}
}
?>
?>
How to use:
- Set $detailsdir to the corresponding uploads folder of your product items.
- In $extensions, include the file types that you want to be displayed (e.g. if you want to show only .pdfs and .docs, ensure that they are in the array and no other extensions).
- If you only have one file for that particular item, then just upload it to the $detailsdir directory and it will be displayed as per mvlcek's version.
- If you want to have more than one file shown item, simply create a sub folder with that item's (well, the slug's) name and upload them there. All entries will be shown (showing n files as "Details: (1) (2) ....(n)").
This will allow you to have any number of files shown per item and no longer need to worry about naming conventions (if you simply put those files in the correct subfolder).