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 8391205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:11:55+00:00 2026-06-09T19:11:55+00:00

I want to download a single .mp3 file from my site but when using

  • 0

I want to download a single .mp3 file from my site but when using this code it forces a .php in Firefox and Safari. But in chrome it will send force the file as inline and play on the page. How can i get them to actually download a .mp3 file?

$track = $_SERVER['QUERY_STRING'];

if (file_exists("/home/user/gets/" .$track)) {
    header("Content-Type: audio/mpeg");
    header('Content-Length: ' . filesize($track));
    header('Content-Disposition: attachment; filename="test.mp3"');
    $str = "/home/user/gets/".$track;
    readfile($str); 
    exit;
} else {
    header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
    echo "no file";
}

I have also tried to download a .zip file as well and changing the Content-Type to application/ocetet-stream but it forces .php files on all browsers.

//$track = $_SERVER['QUERY_STRING'];
$track = 'testfile.zip';
if (file_exists("/home/user/gets/" .$track)) {
    header("Content-Type: application/octet-stream");
    header('Content-Length: ' . filesize($track));
    header('Content-Disposition: attachment; filename="test.mp3"');
    $str = "/home/user/gets/".$track;
    readfile($str); 
    exit;
} else {
    header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
    echo "no file";
}
  • 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-09T19:11:57+00:00Added an answer on June 9, 2026 at 7:11 pm

    I think filesize($track) is wrong, it should be the whole path filesize("/home/user/gets/".$track). This would cause php to output error messages, preventing you from setting the content-length and disposition header.

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

Sidebar

Related Questions

I want to download a single frame of a video file from a server
I want to use HttpOpenRequest to download a file from internet using GET. I
I want to download this picture using Ruby. How do I do that? http://farm1.static.flickr.com/92/218926700_ecedc5fef7_o.jpg
I want to download a single file with Multi-Threads in C#. e.g: Thread1 start
I'm doing a project on java download manager.i want to download a single file(which
Is there a way to programmatically download a single file from a remote Mercurial
I don't have a local code copy/etc, I just want to download a single
what I want: Download a webpage from a server > Save content in a
I want to download a video from the internet in my application. Hence, I
I want to download image from url and store in sdcard's folder. If folder

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.