user3515257 user3515257 - 11 days ago 9
PHP Question

UC browser on force download file type is unknown

I got stuck in a very unusual problem. I am using php force download for downloading video files in my website which works fine in most browsers such as chrome firefox IE used in pc. But UC browser on my windows mobile shows the file extension as unknown(eg: if file is video1.mp4 , my downloaded file is video1.unknown).
Any help welcome.

if(file_exists($myfile))
{
// Add bellow code for mime type
$temp = explode(".",$myfile);
$ext = strtolower(end($temp));
$mime_types = array(

// video
'3gp' => 'video/3gpp',
'3g2' => 'video/3g2',
'avi' => 'video/avi',
'mp4' => 'video/mp4',
'asf' => 'video/asf',
'mov' => 'video/quicktime',
);
if (array_key_exists($ext, $mime_types)){
$mm_type=$mime_types[$ext];
}else{
$mm_type="application/octet-stream";
}
$fname=str_replace(" ","_",$result->TITLE);
//header("Cache-Control: public, must-revalidate");
header("Pragma: public");

header("Content-Type: ".$mm_type);

header('Content-Disposition: attachment; filename='.$fname);
header('Content-Length: '.filesize($myfile));
header("Content-Transfer-Encoding: binary");
ob_clean();
flush();
readfile($myfile);
}
else
{
echo "unable to download";

}

Answer

Adding file extension with the filename solves the issue.

Comments