Вопрос

I have the following link on my website - http://mywebsite/multimedia/pronounciation/265.mp3 which gets me the file bypassing controllers. But I would like to log request and then return this file. So I created controller which logs request and then reroutes to the file:

class Controller_GetSound extends Controller {

    public function action_index() {
        Request::factory('multimedia/pronounciation/265.mp3')
                ->method(Request::POST)
                ->post($this->request->post())
                ->execute();
    }
}

But it doesn't work as expected. How can I return resource file from controller?

Это было полезно?

Решение

Kohana has a send_file function. That function does a good job on splitting large files and sending correct mime types.

@see http://kohanaframework.org/3.3/guide-api/Response#send_file

Your code should be:

class Controller_GetSound extends Controller {

    public function action_index() {

        $this->response->send_file('multimedia/pronounciation/265.mp3',TRUE,array(
            'mime_type' => 'audio/mpeg',
        ))
    }
}

You actually don't really need to set the mime_type. Kohana will find the correct mime_type for your.

Другие советы

It sounds like you want to implement something known as X-Sendfile. I think?

The controller would look something like this:

class Controller_GetSound extends Controller {

    public function action_index() {
        $this->response->headers(array(
            'Content-Type' => 'audio/mpeg'
            'X-Sendfile' => 'multimedia/pronounciation/265.mp3',
        );
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top