logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: php music player
Author
domino123



Joined: 26 Nov 2011
Posts: 7

PostPosted: Sun 18 Dec '11 5:05    Post subject: php music player Reply with quote

Code:
<?php

 // Connects to your Database

 mysql_connect("localhost", "root", "masterlock") or die(mysql_error());

 mysql_select_db("test") or die(mysql_error());

 
 //checks cookies to make sure they are logged in

 if(isset($_COOKIE['ID_my_site']))

 {

    $username = $_COOKIE['ID_my_site'];

    $pass = $_COOKIE['Key_my_site'];

        $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());

    while($info = mysql_fetch_array( $check ))    

       {

 

 //if the cookie has the wrong password, they are taken to the login page

       if ($pass != $info['password'])

          {          header("Location: index.php");

          }

 

 //otherwise they are shown the admin area   

    else

          {

           echo "Admin Area<p>";

 echo "Coming soon music search <p>";
 if ($handle = opendir('/music/music')){
    while (false !== ($file = readdir($handle)))
        echo "$file\n";
    closedir($handle);
}

 echo "<a href=logout.php>Logout</a>";

          }

       }

       }

 else

 

 //if the cookie does not exist, they are taken to the login screen

 {         

 header("Location: index.php");

 }

 ?>



i want to setup music to play from the web like the ones u click the play button on. the music is located in a folder called /music and its locked so no one can download the file or such so i want the file pulled through the php file and played in that php file. any advice or way to do this? also would like to enable a search by author or name feature if i can or have a player that does. i run google chrome which plays the songs when clicked on im not worried about a embeded player if it wont work with the directory locked but i really would like a embeded one if possible. link to site is music.platinum-browser.tk test test for username and password if u want to see how it is. just after logining in go to /test.php instead of members. this is for personal use just dont want people downloading my music
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Sun 18 Dec '11 10:02    Post subject: Reply with quote

well .. someone correct me if I am wrong .. once you give access to the files .. they are fair game for downloading. Unless .. I'm php lame .. but if they were in the DB as I think blobs? .. Mario .. help?
Back to top
domino123



Joined: 26 Nov 2011
Posts: 7

PostPosted: Sun 18 Dec '11 23:27    Post subject: Reply with quote

yea sorta since im the only user im not worried of that. how it was the folder /music/music had links and only way to protect it was with htaccess. im trying to move away from that log in to php logins but the only way to do that is to deny all to /music/music and have a login system in /music that will get the music from /music/music if not log in then they cant get it. but im stuck on how to make it were i can play music from the members area
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Mon 19 Dec '11 12:11    Post subject: Reply with quote

glsmith wrote:
well .. someone correct me if I am wrong .. once you give access to the files .. they are fair game for downloading. Unless .. I'm php lame .. but if they were in the DB as I think blobs? .. Mario .. help?


Don't save that into the DB. At leat I am not a fan of blobs in a DB. Makes it large and lame. The file system is much better.
it is possible to have that files outside of the httpd document root. Than access it via PHP and deliver it to the client.

Code:

<?php
//your login check goes here ...
if($_GET['down']!=""){
   $fp = $_GET['down'];
   if(@is_readable($fp)){
           clearstatcache();
      header("Content-Type: application/force-download");
      header("Content-Transfer-Encoding: binary");
      header("Content-Length: ".@filesize($fp));
      header("Content-Disposition: attachment; filename=\"".@basename($_GET['down'])."\"");
      @readfile($fp);
      die();
   }
   else
   {
      echo 'no file';
   }
}
?>


Kinda like that. Instead of the force-download header you should use the correct one so the player can play it instead of downloading.

Quote:

this is for personal use just dont want people downloading my music


When ever you stream it or something, ppl will be able to record it.
Back to top
domino123



Joined: 26 Nov 2011
Posts: 7

PostPosted: Fri 23 Dec '11 8:18    Post subject: thank you Reply with quote

i cant seem to get that command to work i would love for it to work so where do i enter the folder location for somereason i guess im lost thank you
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Sun 25 Dec '11 17:10    Post subject: Reply with quote

ya, in the url you insert the folder name and the file name like

?down=myfile.mp3

of cause you you pre enter the path in the script. that would make it easier.
Back to top
domino123



Joined: 26 Nov 2011
Posts: 7

PostPosted: Wed 28 Dec '11 0:07    Post subject: Reply with quote

so how would i have it get all of my songs at once and will this show a list too or just download it and like this right



<?php
//your login check goes here ...
if($_GET['down']!="?down=myfile.mp3"){
$fp = $_GET['down'];
if(@is_readable($fp)){
clearstatcache();
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($fp));
header("Content-Disposition: attachment; filename=\"".@basename($_GET['down'])."\"");
@readfile($fp);
die();
}
else
{
echo 'no file';
}
}
?>
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Wed 28 Dec '11 0:33    Post subject: Reply with quote

I thought your already existing list creates that list and you create link in the href to a page with that script and you download it or what ever do with it. You wrote that you wanted a script that pull the mp3 from the folder outside of your document root.

or with that script I gave you, you can put it as source (src) in the embedded player.
Back to top
domino123



Joined: 26 Nov 2011
Posts: 7

PostPosted: Wed 28 Dec '11 2:28    Post subject: Reply with quote

my current list is only a name calling it just list all the files like in test no linking or anything. through the readdir
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Wed 28 Dec '11 20:16    Post subject: Reply with quote

ok, I try to explain it...


  • You generate the list with your readdir stuff
  • in the list the are generated links to a page with the embedded player
  • in src of the player page there is, let's call it grab script, and delivers the file


part of the list generation... in the loop
Code:

...
<li><a href="player.php=?file=<?php echo $file; ?>">Song: <?php echo $file; ?></a>
...


player.php
Code:

<EMBED src="james_script.php?file=<?php echo $_GET['file']; ?>" autostart=true loop=false volume=100 hidden=true><NOEMBED><BGSOUND src="file.wav"></NOEMBED>


Clear?
Back to top
domino123



Joined: 26 Nov 2011
Posts: 7

PostPosted: Thu 29 Dec '11 2:00    Post subject: Reply with quote

yes thank you i believe i understand now
Back to top


Reply to topic   Topic: php music player View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner