0

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

Inge
  • 427
  • 7
  • 20
  • You're not using `$filename`, are you aware of that? – slhck May 04 '13 at 12:54
  • Try `header("Cache-Control: must-revalidate, post-check=0, pre-check=0");` – Baba May 04 '13 at 12:55
  • @Baba If the function branches off to `else` (which is where the error comes from), then whatever's in the `if` isn't relevant to the problem. – slhck May 04 '13 at 12:56
  • Sry for late response. @slhck i know that but just for testing i put $file varaibel in there. So this doesn´t matter. And you´re right, the header doesn´t matter cause it never gets called :( – Inge May 06 '13 at 18:04
  • Try using full path for the $file. Problem is not with restler – Arul Kumaran May 08 '13 at 04:16

1 Answers1

0

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();
Techie
  • 44,706
  • 42
  • 157
  • 243
  • that doesn´t work, the problem is that the code inside the if clause is never called so file_exists seems to have a problem. Maybe something to do with restler htaccess mod_rewrite which is needed in default restler setup? – Inge May 06 '13 at 18:07