Chrome Locks File Reading

Asked

Viewed 275 times

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.

  • 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

  • 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.

1 answer

0


It is not Chrome. Your web server is not allowed to read local files for security reasons (Not allowed to load local Resource = It is not allowed to load local resource [file]). One way around the problem is to simply move your music folder into the folder where your PHP is running. If that 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 error "403 FORBIDDEN" when trying to access them.

  • Thanks for the clarification!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.