CakePHP:使用 Flash 播放器流式传输的 mp3 文件的媒体视图
我有一个带有音频闪存播放器的页面,可以流式传输多个 mp3 文件。该播放器使用一个 XML 文件,其中包含所有这些文件的路径,这些文件位于 webroot 目录的 audio 文件夹中。
我不喜欢的是,用户可以很容易地访问 XML 文件(也在 webroot 目录中)并查看 mp3 文件的路径,然后下载它们,而不仅仅是使用 Flash 播放器。
我看到 CakePHP 有一个叫做 Media Views 的东西,你可以在 webroot 之外设置一个文件夹并将你的文件放在那里,这样用户就无法自由访问它们。 Cake 网站(http://book.cakephp.org/view/1094/Media-Views)中的解释重点是要下载的文件,但我想知道是否可以使用媒体视图来流式传输我的 mp3 文件音频播放器,而不让用户下载它们。或者如果有任何其他没有媒体视图的替代方案也可以工作:)
提前非常感谢!
澄清
这是我正在使用的代码,我想更改:
- 在我的控制器中:
function index() {}
- 在我看来(index.ctp):< /strong>
<embed type="application/x-shockwave-flash" flashvars="audioUrl=/audios/01 Track 01.mp3" src="audio-player.swf"></embed>
=>如何使用媒体视图更改它,以便我的 mp3 文件位于文件夹 app/audios 而不是 app/webroot/audios 中?
这就是我尝试过的:
- 在我的控制器(streams_controller.php)中:
function index() {}
function getFile() {
$this->view = 'Media';
$params = array(
'id' => '01 Track 01.mp3',
'name' => '01 Track 01',
'download' => false,
'extension' => 'mp3',
'path' => APP . 'audios' . DS,
'cache' => true
);
$this->set($params);
}
- 在我看来(index.ctp):
<embed type="application/x-shockwave-flash" flashvars="audioUrl=/streams/getFile" src="audio-player.swf"></embed>
仍然运气不好!我做错了什么?
I have a page with a audio flash player that streams several mp3 files. This player uses an XML file that has the path of all those files, which are in a audio folder in the webroot directory.
What I don't like is that it's pretty easy for a user to get to the XML file (which is also in the webroot directory) and see the paths of the mp3 files, and then download them instead of just using the flash player.
I've seen that CakePHP has something called Media Views, where you can set a folder outside the webroot and place your files there, so users can't freely access them. The explanation in Cake's website (http://book.cakephp.org/view/1094/Media-Views) is focused on files to download, but I would like to know if I can use the Media Views to stream my mp3 files with the audio player without making them downloadable by the users. OR if there's any other alternative without Media Views that would work as well :)
Thanks so much in advance!
CLARIFICATION
This is the code that I'm using that I would like to change:
- In my controller:
function index() {}
- In my view (index.ctp):
<embed type="application/x-shockwave-flash" flashvars="audioUrl=/audios/01 Track 01.mp3" src="audio-player.swf"></embed>
=>How can I change that using Media Views so that my mp3 file is in a folder app/audios instead of app/webroot/audios?
THIS IS WHAT I'VE TRIED:
- In my controller (streams_controller.php):
function index() {}
function getFile() {
$this->view = 'Media';
$params = array(
'id' => '01 Track 01.mp3',
'name' => '01 Track 01',
'download' => false,
'extension' => 'mp3',
'path' => APP . 'audios' . DS,
'cache' => true
);
$this->set($params);
}
- In my view (index.ctp):
<embed type="application/x-shockwave-flash" flashvars="audioUrl=/streams/getFile" src="audio-player.swf"></embed>
STILL NO LUCK! What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
媒体视图似乎正是您所需要的。它将允许您将 mp3 移到 webroot 之外。
仅当您在选项中为“下载”键传递 true 时,Cake 才会发送标头以强制下载。
只要将 if 设置为 false 就可以了。
The Media view seems to be what you need here. It will allow you to move the mp3 outside the webroot.
Cake will send headers to force the download only if you pass true for the 'download' key in options.
Just set if to false and it might work.
我认为,默认情况下,用户可以从 webroot 文件路径或 /controller/action 路径下载文件。
但这很容易通过一些安全实现来克服。
注意:在我看来,如果您使用某种授权,您应该根据他们的 ['User']['id'] 而不是他们的 IP 进行哈希处理
I think, by default, the user will be able to download the file either way, from a webroot file path or from a /controller/action path.
But this is easy to overcome, with a couple of security implementations.
NOTE: in my opinion, if you're using Authorization of some sort, you should hash based on their ['User']['id'] instead of their IP
Cakephp 3x 媒体文件下载闹剧
if ($this->request->is(['post'])) {
$data = $this->请求->数据;
Cakephp 3x media files farce to download
if ($this->request->is(['post'])) {
$data = $this->request->data;