Chrome blocks file reading

0

Good night, Stack Overflow folks, I'm writing a playlist system in PHP, it's still under development so to test the songs I've listed the links of each song in 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 in a new tab Chrome played the song. After many attempts and changes in the source code, I tried debugging in Chrome itself and received as a result Not allowed to load local resource: file: /// home / zenas / Music / [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>";

list.php

<?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>"; 
}

}

}
    
asked by anonymous 16.12.2016 / 02:36

1 answer

0

It's not Chrome. Your Web server is not allowed to do local file reads for security reasons (Not allowed to load local resource). One way to get around the problem is to simply move your music folder into the folder where your PHP is running. If this folder is / var / ww, then: mv /home/zenas/Musica /var/www/Musica

Or, you can make a symbolic link from your Music folder to the Web Server folder: ln -s /home/zenas/Musica /var/www/Musica In the latter case, it is important to configure your web server to allow symbolic links, or you will get the "403 BANNED" error when you try to access them.

    
16.12.2016 / 04:20