I have a custom 404 page for a server serving only MP3s that I want to send a default 'MissingAudio.mp3' file to the client.

When the non-existent MP3 file is requested, FF says that it can't find the file, the original 'non-existent' file name, not the one defined in the 404 page.

I have used the core of this page (changing the content headers to send MP3) many times in the past without problems. It just doesn't seem to work as a custom 404 page.

//Custom 404 error page
//missing.php

  $filepath = "NoLongerAvailable.mp3";
  $path = "./"; 
  $filename = basename($filepath);
  $total = $path.$filepath;

  header('Content-type: audio/mpeg');
  header('Content-Disposition: attachment; filename=' . $filename . ';');
  header("Content-Transfer-Encoding: binary");
  header("Content-Length: ".filesize($total));
  readfile($total);
  exit();

Any thoughts?
Thanks

    you will need an absolute path, as the path to the 404 will depend on where in your site the error was found

      Thanks for the reply. All the files are served from the root directory. Even using a hardcoded absolute file path, I still was unable to send the default MP3 to the client.

      I decided (discovered) that one way to send a default MP3 when the requested file is missing is to use mod_rewrite for all requests of MP3s. I added the below lines to my htaccess file :

      RewriteEngine on
      RewriteRule (.*).mp3$ mp3download.php?file=/$1.mp3

      mp3download.php checks for the existence of the file, and if the file is not found, the default is served.

      Thanks again for the info.

        Write a Reply...