-1

I have a database from which I would like the user to download data I'm trying to download mp3 files. If the file contains, for example, Cyrillic characters, then in Safari I get the file ÐÐ¸Ð·Ð½ÐµÑ lite - ÐÑÐ°Ñ talk.mp3, in other browsers I get a normal file name Бизнес lite - Краш talk.mp3. Here is a sample code. Help, please, what am I doing wrong?

`
$src_file = ROOT_PATH . '/files/uploads/' . substr( $track_file['name'], 0, 2) . '/' . $track_file['name'];
if(file_exists($src_file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'. $track_file['title'] . '.mp3"');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($src_file));
    ob_clean();
    flush();
    readfile($src_file);
    exit;
`

  • Please have a look at https://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http if you haven't already. To be honest, I don't know if there's a solution that works in Safari. – Álvaro González Nov 03 '22 at 10:04
  • Does this answer your question? [How to encode the filename parameter of Content-Disposition header in HTTP?](https://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http) – mikep Aug 10 '23 at 16:49

1 Answers1

-1

would use if else

if user agent safari . you can find browser name by the $_SERVER['HTTP_USER_AGENT']


$src_file = ROOT_PATH . '/files/uploads/' . substr( $track_file['name'], 0, 2) . '/' . $track_file['name'];
if(file_exists($src_file)) {

if($useragent=='safari'){

header('content-type: application/octet-stream');
header('content-Disposition: attachment; filename='.$src_file);
header('Pragma: no-cache');
header('Expires: 0');
readfile($src_file);

}else{

//your current code

}
Ramil Huseynov
  • 350
  • 4
  • 7