title: How do I view text files in a bootstrap modal?
body: <p>I am working on a php web application whereby, a list of files(text) are displayed in a tabular form with buttons to view ,edit or delete  each file.</p>
  
  <p>On click of the view button of any file, it should display a bootstrap modal with the content of that particular file . I have not been able to achieve that so far . </p>
  
  <p>How will I be able to view the content of files in a modal ? Thank you .</p>
  
  <p>Edit :  I strongly suspect it has to do with the php code that reads the contents of the files in the directory . I am sure, I am not doing something right .Specifically, how can a click on a particular view button  display a particular file . Any help with regards to the php code will be highly appreciated .</p>
  
  <pre><code> &lt;?php
             $path='/path/to/files';
             $myDirectory=opendir($path);  
  
             if ($myDirectory==false)
       {
          echo "&lt;br&gt;&lt;br&gt;&lt;div class='container'&gt;&lt;div class='alert alert-danger text-center'&gt;&lt;strong&gt;Error!&lt;/strong&gt; Failed to open Directory &lt;/div&gt;&lt;/div&gt;\n";
           break;
       }
  
             //Gets each entry
             while($entryName=readdir($myDirectory))
             {
                 $dirArray[]=$entryName;
             }     
  
             closedir($myDirectory);
             $indexCount=count($dirArray);
             sort($dirArray);
  
  
             //loops through the array of files 
  
  
                       foreach ($dirArray as $value) {
                         # code...
  
                         $text=file_get_contents('/path/to/files/'.$value);
  
                         $content=str_replace("\n","&lt;br&gt;",$text);
                           $conn[]=$content;
  
                       }
  
  
  
             for($index=0; $index &lt; $indexCount; $index++)
             {
  
                       $name=$dirArray[$index];
  
                     if ( ( strpos($name,'.') === 0 ) | $name == "." | $name == ".." ){
                                          continue;
                          }
  
                       print("
  
                        &lt;tr&gt;
  
                        &lt;td&gt;&lt;span&gt;&lt;/span&gt;&lt;a href='$name'&gt; $name &lt;a&gt;&lt;/td&gt;
                        &lt;td&gt;$path&lt;/td&gt;
  
                        &lt;td class='text-nowrap'&gt;&lt;button type='button' class = 'btn btn-default' data-toggle='modal' data-target='#myModal' &gt; View &lt;/button&gt;&lt;/td&gt;
  
                        &lt;td&gt;&lt;button class = 'btn btn-default' data-toggle='modal' data-target='#edit'&gt; Edit &lt;/button&gt; &lt;/td&gt;
  
                        &lt;td&gt;&lt;a href='delete.php?name=".$name."'&gt;&lt;button class = 'btn btn-default' &gt; Delete &lt;/button&gt;&lt;/a&gt;&lt;/td&gt;
  
                        &lt;/tr&gt; 
  
  
                    ");
  
  
  
             }     
  
  
  
  
  
  
  ?&gt;
  
   &lt;div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'&gt;
                &lt;div class='modal-dialog' role='document'&gt;
                  &lt;div class='modal-content'&gt; 
                  &lt;div class='modal-header'&gt; 
                   &lt;button type='button' class='close' data-dismiss='modal' aria-label='Close'&gt;&lt;span aria-hidden='true'&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
                    &lt;h4 class='modal-title' id='myModalLabel'&gt;&lt;/h4&gt;
                 &lt;/div&gt; 
                  &lt;div class='modal-body'&gt; 
  
                     &lt;div&gt; &lt;?php 
  
                        //print_r($conn)  
  
  
                            foreach ($conn as $key =&gt; $value) {
  
                                 echo $value;
  
                            }
                     ?&gt; &lt;/div&gt;
                     &lt;div&gt;
  
                     &lt;/div&gt;                  
  
   &lt;/div&gt;
                   &lt;div class='modal-footer'&gt;
                    &lt;button type='button' class='btn btn-default' data-dismiss='modal'&gt;Close&lt;/button&gt;   
                       &lt;/div&gt;   
                  &lt;/div&gt;   
                   &lt;/div&gt;  
                  &lt;/div&gt;
  </code></pre>