I tried doing a $this->redirect() in the view to the file, eg.
(/app/views/resources/files/foo) but it still came up with a missing
controller error. The following code allows me to do what I'm trying.
Hope someone finds it useful.

Note that the 'dl' type makes the browser create a "Save As" dialog. To
turn that off and make the browser decide what to do depending on the
mime-type, comment out the "Content-disposition" line.

Thanks for your help, all.
-Ian

<?php
        $this->pageTitle = $resource['Resource']['name'];
        $location = $resource['Resource']['location'];
        $file =
"{$_SERVER['DOCUMENT_ROOT']}/app/views/resources/files/{$location}";
?>

<?php
        if($resource['Resource']['type'] === 'include') {
                //echo $this->render("files/{$location}");
                include("$file.thtml");
        } elseif ($resource['Resource']['type'] === 'link') {
                $this->controller->redirect($location);
        } elseif ($resource['Resource']['type'] === 'dl') {
                $this->layout = null;
                $this->autoLayout = false;

                $mimeType = mime_content_type($file);
                if (isset($mimeType) && strlen($mimeType) > 0)
                        header("Content-Type: $mimeType");
                header("Content-Disposition: attachment; filename=" .
basename($file));
                header("Content-Length: " . filesize($file));
                @readfile ($file);
                die;
        }
?>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to