强制下载restler函数调用

时间:2013-05-04 12:52:45

标签: php restler

我在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>";
    }
}

问题是文件是否正确,但没有文件下载 被迫的。 失败在哪里? 它始终返回“文件不存在但它确实存在。 我用强制下载一个php搜索了不同的问题,但这似乎与restler有问题?

THX INGO

1 个答案:

答案 0 :(得分:0)

您可以尝试下面的代码,这恰好可以正常工作

$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();