HTML : file-download: controle favicon and Tab-Title

痴心易碎 提交于 2021-01-28 06:02:33

问题


My file download works great. The file is delivered correctly. But I want to make it prettier.

Is there a way to set a favicon and a window title, if I click on a html-download link to a file in a new tab?

the file is generated and streamed by php.

client part:

<a target="_blank" tabindex="0" href="/path/to/file-download/interface" >

server stream, while $file is some array holding file information:

    if (file_exists($file['path'])) {
        $finfo = finfo_open(FILEINFO_MIME_TYPE); 
        $mime = finfo_file($finfo, $file['path']);

        if( strstr($mime, "image") !== false ){
            header('Content-Type: '.$mime);
            header('Content-Disposition: filename='.basename($file['path']));
        } else {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename='.basename($file['path']));
        }

        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($file['path']));
        ob_clean();
        flush();
        readfile($file['path']);
        exit;
    } else {
        error_log("File for download >".$file['path']."< not found.");
        return false;
    }

UPDATE An additional problem is, that there is a favicon already in the root folder, but I want to show a different one.

来源:https://stackoverflow.com/questions/44002043/html-file-download-controle-favicon-and-tab-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!