Great!
You've helped me so much!
Especially the link options that look like "__('Download this file',
true) " did it. Didn't have the chance yet to dig into those details.
For the other newbes:
Make sure you don't print anything (with e.g. "pr()" ) before you
start sending headers+the file because it messes up the headers.
Maybe a bit redundant but I'll post my exact solution below, for the
sake of showing an example, although it looks alot like the above.

In my view:
<?php echo $html->link(__('dowload it', true),
DS.'users'.DS.'downloadFile'.DS.$file_id); ?>

In my controller:
        function downloadFile($id){
                $user = $this->Session->read();
                $valid = $this->Relation->find(array('user_id' => $user['User']
['id'], 'audiofile_id' => $id));
                if(!empty($valid)){
                        $this->AudioFile->id = $id;
                        $dbEntry = $this->AudioFile->read();
                        $file = 
MUSIC_UPLOAD_PATH.DS.$dbEntry['AudioFile']['file_id'].
$dbEntry['AudioFile']['type'];
                        $data = file_get_contents($file);
                        $size = filesize($file);
                        $song = $dbEntry['AudioFile']['name'];
                        if(isset($_SERVER['HTTP_USER_AGENT']) &&
strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
                                header('Content-Type: 
application/force-download');
                        }else{
                                header('Content-Type: audio/mpeg');
                header('Content-Length: '. $size);
                                header('Content-disposition: attachment; 
filename="' .
$song .'"');
                                echo $data;
                        }else{
                                $this->redirect($this->referer(), 403);
                        }
                }else{
                        $this->redirect(DS.'users'.DS.'logout'); //opzouten
                        exit();
                }
        }

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to