Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8394347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:02:07+00:00 2026-06-09T20:02:07+00:00

I am embedding some mp3 files on my website. The problem is some of

  • 0

I am embedding some mp3 files on my website. The problem is some of the names are different and my website does not know how to embed – unless I define all the files with the correct names.

For example,

http://example.com/chapter1/book-[some random name].001.mp3

I have set up my website so it embeds like this

http://example.com/chapter1/book.001.mp3

Is there any possible solution that I can use with php so it auto fills the [some random name].

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:02:08+00:00Added an answer on June 9, 2026 at 8:02 pm

    You have some options,

    1. Output the path to the file correctly (easiest)

    2. Build and store a registry of the mp3s in a db or flat file and use mod_rewrite to pass the parameters to a loader script. (Example below)

    <?php 
    /* mod_rewrite  .htaccess in chapters folder
    RewriteEngine On
    Options -Indexes
    RewriteBase /chapter1
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*).mp3$ index.php?loadmp3=$1 [L]
    */
    $mp3_dir='./mp3s/';
    //Example passed url: http://localhost/chapter1/book.002.mp3
    if(isset($_GET['loadmp3'])){
        $real_path = get_mp3_list($_GET['loadmp3']);
        if($real_path != false){
            //Result:  ./mp3s/book-next_random_name.002.mp3
            print_r($real_path);
            //Pass the url to a streamer script
        }else{
            //not found
        }
    }
    
    /**
     * Build & cache, search for mp3 from array
     */
    function get_mp3_list($search){
        global $mp3_dir;
        if(file_exists($mp3_dir.'mp3s.json')){
            $list = json_decode(file_get_contents($mp3_dir.'mp3s.json'),true);
        }else{
            $mp3s = glob($mp3_dir."*.mp3");
            $list = array();
            foreach($mp3s as $mp3){
                if(preg_match("#(\w+)-(\w+).(\d+).mp3#", $mp3, $match)){
                    $list[]=array('location'=>$mp3,
                    'type'=>$match[1],
                    'name'=>$match[2],
                    'episode'=>$match[3]);
                }
                if(!empty($list)){file_put_contents($mp3_dir.'mp3s.json', json_encode($list));}
            }
        }
    
        $search = explode('.',$search,2);
        foreach($list as $mp3){
            if($mp3['type'] == $search[0] && $mp3['episode'] == $search[1]){
                return $mp3['location'];
            }
        }
        return false;
    }
    /*
    $list Example Array 
    (
        [0] => Array
            (
                [location] => ./mp3s/book-next_random_name.002.mp3
                [type] => book
                [name] => next_random_name
                [episode] => 002
            )
    
        [1] => Array
            (
                [location] => ./mp3s/book-some_random_name.001.mp3
                [type] => book
                [name] => some_random_name
                [episode] => 001
            )
    
    )
    */
    ?>
    

    Hope it helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm embedding dates from google calendar into a website, and it's all working, with
I'm having a problem with youtube video embedding; In some places on my site
I have some site where I am embedding a couple of youtube videos in
I am embedding Spidermonkey in my C++ application. I need to implementing some custom
I'm developing a free application and would like to make some money by embedding
Embedding HTML within .PHP files is one of the primary functionalities of PHP, but
When embedding assets of any size in the following manner - [Embed(source=../../assets/Assets.swf, symbol=LargeButton)] public
I am embedding my videos with JW player http://www.longtailvideo.com/players/ and I have a problem
The Flash IDE is capable of embedding many types of uncompressed sound files, including
I need to convert some images to base64 for embedding into my CSS... anyone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.