This question already has an answer here:
-
Is it possible to protect from downloading a video from a site
10 answers
I have a PHP script that is responsible for outputing and streaming MP3 files to the browser, my questions is
How can I prevent downloading the MP3 file?
*knowing that I tried using HTTP Referrer and it worked ((only on my localhost)) detecting the direct downloads of the file but not on my server
How can I prevent downloading the MP3 file?
You can't.
You can't send someone data in a way that they can't receive the data. If they can play it, they can download it. It's the same action.
At best, you can digitally watermark your media with unique identifiers so that if someone re-shares the content, you can trace it back. You can also prevent someone from sharing a link to media by using signed URLs or otherwise one-time-use (or time-limited) URLs.