0
I have a page in PHP that lists the files of 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>
What happens if you click on the link? And what should this tag do
video
at the end of the code?– Woss
After clicking on the link nothing happens...!
– alexjosesilva
And if you leave the variable
$endereco
empty?– Woss
Fatal error: Uncaught Runtimeexception: Directory name must not be Empty. in C: xampp htdocs www buscar.php:8 Stack trace: #0 C: xampp htdocs www buscar.php(8): Directoryiterator->__Construct(') #1 {main} thrown in C: xampp htdocs www buscar.php on line 8
– alexjosesilva
Obvious kkk error mine. Return the variable value and just remove it from
$link
. Let$link
only with the file name.– Woss
I can’t open the file and I can’t see it in the video tag!
– alexjosesilva
$link with filename: OK
– alexjosesilva
Perfect everything working out!
– alexjosesilva