Error opening file in PHP page

0

I have a page in PHP that lists the files in a folder from a search. In the result has a link to the file in order to open it. However, it is not possible to open the listed files.

Code index.php

<form name="frmBusca" method="POST" action="buscar.php">

    <input type="text" name="buscar">
    <input type="submit" name="pesquisa" value="Buscar">

</form>

Code search.php

    <?php
    //Arquivo para buscar video dentro do explorer
    $video = $_POST['buscar'];

    $endereco = "C:/xampp/htdocs/www/";


    $iterator = new DirectoryIterator($endereco);

    foreach ( $iterator as $entry ) {

        if( ($entry->getFilename()) == $video){
            echo $entry->getFilename()," "; 
            $link = $endereco.$entry->getFilename(); 
            echo "<a href='$link'>".$entry->getFilename()."</a>";
            echo "<br>";
        }

    }

?>


<video width="320" height="240" controls>
  <source src='<?php echo $link; ?>' type="video/mp4">
</video>

    
asked by anonymous 01.07.2017 / 01:38

1 answer

0

Fixing the .php file

 <?php
    //Arquivo para buscar video dentro do explorer
    $video = $_POST['buscar'];

    $endereco = "C:/xampp/htdocs/www/";


    $iterator = new DirectoryIterator($endereco);

    foreach ( $iterator as $entry ) {

        if( ($entry->getFilename()) == $video){
            echo $entry->getFilename()," "; 
            $link = $entry->getFilename(); 
            echo "<a href='$link' target='_blank'>".$entry->getFilename()."</a>";
            echo "<br>";
        }

    }


?>


<video width="320" height="240" controls>
  <source src='<?php echo $link; ?>' type="video/mp4">
</video>

    
01.07.2017 / 02:05