simun Posted May 29, 2009 Share Posted May 29, 2009 i have a folder on my server with many type of files (.jpg .txt .pdf) i need to list all .pdf files on my page how to do that? Quote Link to comment https://forums.phpfreaks.com/topic/160139-php-get-onley-pdf-files/ Share on other sites More sharing options...
dmcke5 Posted May 29, 2009 Share Posted May 29, 2009 Is It a dynamic list or a static list? (I.e Will the files be changing?) Because if not, im sure simple Href's Would do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/160139-php-get-onley-pdf-files/#findComment-844880 Share on other sites More sharing options...
simun Posted May 29, 2009 Author Share Posted May 29, 2009 it is a dinamic list my page look like this and all files shows like thay are a picture <?php include('templates/' . $__config['template'] . '/header.php'); include('templates/' . $__config['template'] . '/menu.php'); include('templates/' . $__config['template'] . '/menu2.php'); $object->gallery->getPhotos(); ?> <div id="content"> <h1><?=$object->{'naziv_' . $__language}?></h1> <div class="clear"></div> <div class="realestate-details"> <p><?=$object->{'opis_' . $__language}?></p> <div class="images-details"> <?php if (is_array($object->gallery->photos)) { foreach($object->gallery->photos as $photo) { ?> <a rel="lightbox[image]" rel="photos-<?php echo $object->sifra; ?>" href="/images/cache/objects/<?=$object->id?>/<?=$photo['filename']?>/w-500.jpg"><? ?><img style=" border-style: solid; border-width: 1px; border-color:#BFC6C8; padding: 2px;" alt="" src="/images/cache/objects/<?=$object->id?>/<?=$photo['filename']?>/h-100.jpg" /><? ?></a> <?php } } ?> </div> </div> </div> <div class="clear"></div> <div style="height:23px; width:1047px; background-image: url(/images/sjena_bot.jpg); margin-bottom:20px;"></div> <?php include('templates/' . $__config['template'] . '/footer.php'); ?> now i need to sperate pictures from pdf files any help? Quote Link to comment https://forums.phpfreaks.com/topic/160139-php-get-onley-pdf-files/#findComment-844883 Share on other sites More sharing options...
DarkSuperHero Posted May 29, 2009 Share Posted May 29, 2009 if your server is running PHP 5 then you can use the following code... $dir = 'files/home'; //directory you want to iterate through foreach (new DirectoryIterator($files) as $fileInfo) { if($fileInfo->isDot()) continue; //if listing is a dot dont do anything continue with the script if(preg_match("/(\.pdf)+/",$fileInfo->getFilename())) //if the file name contains '.pdf' then...echo location or do something... { echo $fileInfo->getFilename() . "<br>\n"; } } http://us2.php.net/directoryiterator - Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/160139-php-get-onley-pdf-files/#findComment-844884 Share on other sites More sharing options...
Daniel0 Posted May 29, 2009 Share Posted May 29, 2009 Would be much easier to just use glob... $files = glob('/path/to/files/*.pdf'); Quote Link to comment https://forums.phpfreaks.com/topic/160139-php-get-onley-pdf-files/#findComment-844886 Share on other sites More sharing options...
simun Posted May 29, 2009 Author Share Posted May 29, 2009 sorrrrry i have added a wrong page before here is my original page <?php $photos = getGallery($__config['paths']['photos']['products'] . $product['id'] . '/'); ?> <?php if (is_array($subcategory)) { ?> <h2 style="padding-bottom:20px;"><a href="#" onClick="history.go(-1)"><?=$category['title_' . $__language]?> - <?=$subcategory['title_' . $__language]?></a></h2> <?php } else { ?> <h2><a style="color:#5C6668" href="/<?=$__language?>/<?=$__query[2]?>/<?=$__query[3]?>"><?=$category['title_' . $__language]?></a></h2> <?php } ?> <div class="product-details"> <h4><?=$product['title_' . $__language]?></h4> <p><?=$product['description_' . $__language]?></p><br > <?php if (is_array($photos)) { foreach($photos as $photo) { ?> <a rel="lightbox[image]" title="<?=$photos[1]['title']?>" href="/images/cache/products/<?=$photo['filename']?>/<?=$product['id']?>/w-480.jpg"><div style="padding-right:5.2px; float:left;"><img src="/images/cache/products/<?=$photo['filename']?>/<?=$product['id']?>/h-100.jpg" alt="<?=$photos[1]['title']?>" title="<?=$photos[1]['title']?>" /></div> </a> <?php } } ?> <div class="clear"></div> <ul> <br > </ul> </div> now pictures and pdf files show together, and i cant see pdf files becouse it try to open with jpg extension i need to sperate my pictures and pdf files from jpg files i tryed glob function but i cat make it work becouse of ma poor php knowledge please some sugestion???? Quote Link to comment https://forums.phpfreaks.com/topic/160139-php-get-onley-pdf-files/#findComment-844897 Share on other sites More sharing options...
simun Posted May 29, 2009 Author Share Posted May 29, 2009 or how to make that this script shows onley jpg and jepg files? <?php $photos = getGallery($__config['paths']['photos']['products'] . $product['id'] . '/'); ?> <?php if (is_array($photos)) { foreach($photos as $photo) { ?> <a rel="lightbox[image]" title="<?=$photos[1]['title']?>" href="/images/cache/products/<?=$photo['filename']?>/<?=$product['id']?>/w-480.jpg"><div style="padding-right:5.2px; float:left;"><img src="/images/cache/products/<?=$photo['filename']?>/<?=$product['id']?>/h-100.jpg" alt="<?=$photos[1]['title']?>" title="<?=$photos[1]['title']?>" /></div></a> <?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160139-php-get-onley-pdf-files/#findComment-844918 Share on other sites More sharing options...
Daniel0 Posted May 29, 2009 Share Posted May 29, 2009 You were already shown how to check the extension. How about you show some initiative yourself instead of just demanding that other people write your code? Quote Link to comment https://forums.phpfreaks.com/topic/160139-php-get-onley-pdf-files/#findComment-844921 Share on other sites More sharing options...
simun Posted May 29, 2009 Author Share Posted May 29, 2009 daniel im trying and trying it myself but i cant get it work Quote Link to comment https://forums.phpfreaks.com/topic/160139-php-get-onley-pdf-files/#findComment-844926 Share on other sites More sharing options...
DarkSuperHero Posted May 29, 2009 Share Posted May 29, 2009 so is this a 3rd party script? Maybe you can get some help from the creators? whats the name of the script your using? I'm not entirely sure how the code works, but look like it was design explicitly for use with images... My guess is this information is passed on to yet another script which handle the image request and such... Also I think the getGallery function gets all the files...you need to add a conditional statement like... if(preg_match("/(\.pdf)+/",$photo)) //if the file name contains '.pdf' then...echo location or do something... { echo "this is a pdf<br>\n"; } else { echo "this is a regular jpg<br>\n"; } Also, how much PHP do you know? how new are you to this? daniel im trying and trying it myself but i cant get it work Next try, post it here and we can point you in the right direction.... Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/160139-php-get-onley-pdf-files/#findComment-845012 Share on other sites More sharing options...
Daniel0 Posted May 29, 2009 Share Posted May 29, 2009 You'd want that regex to be /\.pdf$/ though. If you want to include others you can do like /\.(foo|bar|baz)$/. Quote Link to comment https://forums.phpfreaks.com/topic/160139-php-get-onley-pdf-files/#findComment-845017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.