swfupload 和 cakephp 集成时, session 不能传递的问题

April 8th, 2009  | Tags: ,

嗯, 外国友人很好的解决了这个问题, 简单来说, 最多三步:

1. 通过swfupload传递 session_id 到上传文件的action:

<script type="text/javascript">
var upload_url = '<?php echo $html->url('/uploads/upload/'.$session->id()) ?>';
</script>

2. 在controller里设置session_id:

<?php
class UploadsController extends AppController {

    var $name = 'Uploads';
    var $components = array('SwfUpload');
    var $helpers = array('Html', 'Javascript');

    function beforeFilter() {

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

        parent::beforeFilter();

    }

    function upload() {

        if (isset($this->params['form']['Filedata'])) {
            // process your upload in here
            // and you can read from or write to the session
            // as you would normally
        }

    }

}
?>

3. 如果还没有正确运行:

Configure::write(‘Security.level’, ‘medium’);

嗯,基本上就解决了 原帖地址: http://blogs.bigfish.tv/adam/2008/04/01/cakephp-12-sessions-and-swfupload/ by Adam Royle

No comments yet.
TOP