Results 1 to 2 of 2

Thread: New browser tabs for pdf files from glob-created list?

  1. #1
    Join Date
    Oct 2008
    Location
    England
    Beans
    171
    Distro
    Xubuntu 16.04 Xenial Xerus

    New browser tabs for pdf files from glob-created list?

    To list a large number of sheet-music pdfs on a website, I'm using this at the top of my php/html file:

    PHP Code:
    <?php
    header
    ('Content-Type: text/html; charset=utf-8');
    function 
    getFiles(){
        
    $files=array();
        if(
    $dir=opendir('.')){
            while(
    $file=readdir($dir)) {
                if(
    $file!='.' && $file!='..'){
                    
    $files[]=($file);
                }   
            }
            
    closedir($dir);
        }
        
    natsort($files); //sort
        
    return $files;
    }
    ?>
    ... then in the <ul> bit of the html section I have this:

    HTML Code:
     <? foreach (glob("*.pdf") as $file)
    	echo "<li name=\"".$file."\"><a href=\"".$file."\">$file</a></li>";
        ?>
    It works fine, except that when clicked on, the pdf replaces the web page content in the browser, and I would prefer it to appear in a separate browser tab.
    I've tried inserting "_blank" in various places but it kills the page, so I'm obviously not doing it right (I'm a musician, not a programmer!).
    How can I get this otherwise successful set-up to trigger a new browser tab for each tune clicked?
    Thanks

  2. #2
    Join Date
    Oct 2008
    Location
    England
    Beans
    171
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: New browser tabs for pdf files from glob-created list?

    OK now ... changing the template bit as follows did the trick:

    HTML Code:
    <?php
    foreach (glob("*.pdf") as $file) {
        echo '<li name="'.$file.'"><a href="'.$file.'" target="_blank">'.$file.'</a></li>';
    }
    ?>

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •