PHP创建下载链接


PHP Create Download Link

<?php
    $file = SEVENCE_DATA_ROOT."/resource/devdemo/promo_card.tiff";
    header('Content-Description: File Transfer');
    header('Content-type: application/tiff');
    header("Content-Type: application/force-download");// some browsers need this
    header("Content-Disposition: attachment; filename=promo_card.tiff");
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
?>

我的问题是下载的图像无法查看。有人能帮我解决这个问题吗?

Content-Type: application/force-download");// some browsers need this

没有浏览器需要这个。这是一个肮脏的小故障。

文件无法打开的原因:

  1. 脚本开头有空格或不可见字符

  2. 你正在加载文件的路径可能是错误的,它甚至不读取它(下载的文件有多大?)

  3. 文件已经损坏

  4. 您没有tiff -viewer

正确的mime类型是image/tiff(而不是application/tiff)