dts777777 2013-05-04 12:52
浏览 30

强制下载restler函数调用

I got the following function in restler

/**
 * get updateFiles by name
 *
 * one could get the last update file
 *
 * @status 201
 * @return file
 */
function getupdateFile($filename) {

    $file = 'Plakat.jpg';

    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit;
    }
    else {
        return "<h1>Content error</h1><p>The file does not exist!(".dirname(__FILE__).'/'.($file).")</p>";
    }
}

The problem is that the file is there permissions are correct but no file download is forced. Where is the failure? It always return "The file does not exist but it does. I searched for different problems with force download an php but this seems to be a problem with restler?

Thx Ingo

  • 写回答

1条回答 默认 最新

  • drze7794 2013-05-04 12:57
    关注

    You can try this code below which happens to work fine

    $file = 'Plakat.jpg';
    if(file_exists($file))
    {
        header("Content-Type: image/png");
        header('Content-Disposition: attachment; filename="ImageName.png"');
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        readfile($file);
    }
    
    exit();
    
    评论

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理