Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Banned
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Play MP3 File Through Link

    Hello!

    I have the following code, that uploads files to a "Upload" directory on the server, and stores the files path in a database.

    Code:
    mysql_select_db("MP3s", $con);
    
    if (($_FILES["file"]["type"] == "audio/mpeg"))
    {
      if ($_FILES["file"]["error"] > 0)
      {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
      }
      else
      {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    
        if (file_exists("upload/" . $_FILES["file"]["name"]))
        {
          echo $_FILES["file"]["name"] . " already exists. ";
        }
        else
        {
          $file = ("upload/" . $_FILES["file"]["name"]);
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "upload/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
          
          mysql_query("INSERT INTO Music (Path)
          VALUES('$file')");    
        }
      }
    }
    else
    {
      echo "Invalid file";
    }
    How do I adapt the below code to link to the mp3 file contain in the "Upload" folder, in order to play the file.

    Code:
    <?php
    $con = mysql_connect("localhost","peter","abc123");
    if (!$con)
    {
      die(mysql_error());
    }
    
    mysql_select_db("MP3s", $con);
    
    $result = mysql_query("SELECT * FROM Music");
    
    while($row = mysql_fetch_array($result))
    {
      echo '<a href="Display.php?Path='.$row['Path'].'">'.$row['Path'].'</a>';
    } 
    
    mysql_close($con);
    ?>

  • #2
    Registered User
    Join Date
    Oct 2007
    Posts
    55
    Thanks
    4
    Thanked 2 Times in 2 Posts
    i don't have much time to read your information, but here's what i know. i'm pretty sure you can play music files on click via link:

    PHP Code:
    <?php
    // query to retrieve path to song
    $url "the url to the music file";
    echo 
    "<a href=\"" $url "\">play song</a>";
    ?>

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    If the browser has a plugin that supports it.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,538
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    You could also use a free MP3 Flash Player.

    See this example:
    http://www.catpin.com/streaming.php

  • #5
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    mlseim, that's cool player


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •