0
Good evening, people of Stack Overflow, I am writing a playlist system in PHP, it is still in development so to test the execution of the songs I listed the links of each song of the chosen directory, but then the links did not take me to the file as in file://home/(...)musica.mp3, but by copying the link and pasting it into a new tab Chrome played the song. After many attempts and changes to the source code, I tried debugging Chrome itself and received as a result Not allowed to load local Resource: file://home/Zenas/Musica/[1967]%20-%20Magical%20Mystery%20Tour/04%20-%20Blue%20Jay%20Way.mp3. How to solve this problem?! Here are the codes:
Index.php
<?php
header('Content-type: text/html; charset=ISO-8859-1');
echo '<form action="list.php">';
echo "<h4>Write your songs folder</h4><br>";
echo "<h5>(DON'T WRITE A BAR IN THE END OR WRITE ANY SPECIAL CHARACTER)</h5>";
echo '<input type="text" name="folder">';
echo '<input type="submit">';
echo "</form>";
php list.
<?php
header('Content-type: text/html; charset=ISO-8859-1');
$folder = $_GET["folder"];
$files = "{$folder}/".$_GET['/*.*'];
if(isset($_GET['folder']) && file_exists("{$folder}/".$_GET['/*.*'])){
$fold = opendir($folder);
while (false !== ($filename = readdir($fold))) {
if (substr($filename,-4) == ".mp3") {
echo "<a href=\"file://$folder/$filename\">$filename</a><br>";
}
}
}
You cannot open files by protocol
file://
. Basic restriction on safety.– Daniel Omine
I don’t understand, but then why when using file:// in a new tab can I access the file? Anyway, when I remove the file:// from the code, PHP interprets that the link leads to a folder within localhost, which is not the case. But thanks for trying =D
– Zenas
For HTML, opening a local file is not allowed. When you put it directly in the URL bar, the browser takes you directly to the filesystem. There is no block in this case because it is you who explicitly put the address. If you want to open this file normally using HTML, put it in the http protocol.
– Daniel Omine