CakePHP 媒体插件和 SWFUpload

发布于 2024-10-15 06:21:41 字数 136 浏览 3 评论 0原文


有没有人曾经将 CakePHP 媒体插件与 SWFUpload 或任何 flash/ajax 上传器结合使用?我在任何地方都找不到这方面的任何文档或代码示例。

任何想法/建议都是非常受欢迎的。

谢谢,
米^e

Has anyone ever used CakePHP Media Plugin in conjunction with SWFUpload or any flash/ajax uploaders? I can't find any documentation or code samples on this anywhere.

Any ideas/suggestions are most welcome.

Thanks,
m^e

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千笙结 2024-10-22 06:21:41

我已经成功地使用 CakePHP 1.3、Uploadify (http://www.uploadify.com/) 和 Miles Johnson 的 Uploader 插件 (http://www.milesj.me/resources/script/uploader-plugin) 完成了一些事情)。

需要一些摆弄才能让一切正常工作,您需要阅读所涉及的每个部分的文档,以使一切按照您需要的方式工作,但这就是我的管理方式:

在您的看法:
包括必要的 Javascript 库:jQuery、SWFObject 和 Uploadify。
插入 Uploadify 脚本将替换为 Flash 上传程序的 元素。
然后插入用于指定 Uploadify 设置的 jQuery 代码(详细信息请参阅 Uploadify 文档)。
设置 Uploadify 发布到的 URL 时,请务必将会话 ID 作为参数之一包含在内。在我的示例中,我将其作为第一个参数传递(请参阅下面的 Controller beforeFilter 以了解它的作用)。

在你的控制器中:
包含 Uploader 插件的 Uploader 组件。
将类似的内容添加到 beforeFilter:

    function beforeFilter() {
    if ($this->action == 'upload') {
        $this->Session->id($this->params['pass'][0]);
        $this->Session->start();
    }
    parent::beforeFilter();
}

创建一个操作来执行上传。我的看起来像这样:

    function upload(){
    Configure::write('debug', 0);
    $this->autoRender = false;  
        if (isset($this->params['form']['Filedata'])) {
    $this->data['Upload'] = $this->params['form'];
    $data = $this->Uploader->upload('Filedata');
    }
}

这就是它的本质。

然而,也有一些问题。

我将会话 ID 传递给控制器​​,并使用该 ID 启动一个新会话,因为 Uploadify 发布到 URL 的帖子可以被视为来自不同的用户代理,这可能会导致错误。您可以通过将浏览器的会话 ID 传递给上传操作并在 beforeFilter 中使用该 ID 启动新会话来解决此问题,如上所示。

此外,上传器组件具有内置的 mimetype 验证。但是,Uploadify 提供的 Flash 上传程序会发送带有某种“flash 文件上传”mime 类型的每个文件,而不管原始文件的 mime 类型如何。我通过直接在上传器插件的代码中禁用验证来解决这个问题。这意味着如果您想验证上传文件的 mimetypes,您必须将其添加到其他地方。

抱歉,这太模糊了,但我不久前这样做了,我不记得所有细节了。不过,我希望它能帮助您指明正确的方向。

I've managed to accomplish something along these lines using CakePHP 1.3, Uploadify (http://www.uploadify.com/) and Miles Johnson's Uploader plugin (http://www.milesj.me/resources/script/uploader-plugin).

It took a bit of fiddling to get everything to work correctly and you'll want to read over the documentation for each of the pieces involved to get everything to work the way you need it to, but this is how I managed it:

In your view:
Include the necessary Javascript libs: jQuery, SWFObject, and Uploadify.
Insert the <input> element that the Uploadify script will replace with the Flash uploader.
Then insert the jQuery code for specifying the Uploadify settings (details in the Uploadify docs).
When setting the URL for Uploadify to post to, be sure to include the session ID as one of the arguments. In my example I've passed it as the first argument (see the Controller beforeFilter below to see what's done with it).

In your controller:
Include the Uploader plugin's Uploader component.
Add something like this to the beforeFilter:

    function beforeFilter() {
    if ($this->action == 'upload') {
        $this->Session->id($this->params['pass'][0]);
        $this->Session->start();
    }
    parent::beforeFilter();
}

Create an action to do the uploads. Mine looks something like this:

    function upload(){
    Configure::write('debug', 0);
    $this->autoRender = false;  
        if (isset($this->params['form']['Filedata'])) {
    $this->data['Upload'] = $this->params['form'];
    $data = $this->Uploader->upload('Filedata');
    }
}

That's the essence of it.

There are a couple of gotchas, however.

I pass the session ID to the controller and start a new session with that ID because Uploadify's post to the URL can be seen as coming from a different User Agent and this can cause errors. You can get around this by passing the browser's session ID to the upload action and starting a new session with that ID in the beforeFilter as shown above.

Also, the Uploader component has built-in mimetype validation. However, the Flash uploader that Uploadify provides sends every file with some kind of "file-uploaded-by-flash" mimetype regardless of the mimetype of the original file. I got around this by disabling validation directly in the Uploader plugin's code. This means that if you want to validate the mimetypes of the uploaded files you'll have to add it in elsewhere.

Sorry that this is so vague, but I did this a while ago and I don't remember all the details. However, I hope it helps point you in the right direction.

友欢 2024-10-22 06:21:41

我找到了这个教程,它运行得很好。
http://pixelcone.com/tutorial/ ajax-文件上传-使用-jquery-and-cakephp-media-plugin/
Cakephp Media 插件确实是一个杰作。希望稳定版本尽快发布。

I found this tutorial and it works perfectly fine.
http://pixelcone.com/tutorial/ajax-file-upload-using-jquery-and-cakephp-media-plugin/
Cakephp Media plugin is really a masterpiece. Hopes the stable version will be released soon.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文