我在 CakePHP 中使用 jquery uploadify,我遇到了 $_SESSION 的问题,因为下面的操作通过 $ this-> request-> params ['named'] ['uid' 接收用户 ID ] 的问题是,使用 uploadify 启用的操作执行了两次,但第二个数据 $ this-> request-> params ['named'] ['uid'] 丢失了。
以下是简化的代码,以便更好地理解。
FilesController.php / index **运行两次
public function index() {
$id = $this->request->params['named']['uid'];
$us = $this->User->findById($id)['User'];
$dir = UPLOAD_DIR . $us['id'] . '/';
CakeSession::write('Files.atual', $dir);
$this->set('u', $us);
//$this->autoRender = false;
}
Views/Elements/up.ctp //启用 Uploadify
<?php $timestamp = time(); ?>
$(function() {
$('#file_upload').uploadify({
'formData' : {
'timestamp' : '<?php echo $timestamp; ?>',
'token' : '<?php echo md5('unique_salt' . $timestamp); ?>'
},
'swf' : '<?= $this->request->webroot; ?>uploadify.swf',
'preventCaching' : false,
'uploader' : '<?= $this->request->webroot; ?>uploadify.php?session_id=<?php echo(session_id()); ?>',
'buttonClass' : 'button icon-paperclip',
'buttonText' : 'Enviar Arquivos',
'onUploadSuccess' : function(file, data, response) {
$('.files-icons').load('<?= $this->request->webroot; ?>files/reload/<?= $u['id'] ?>');
}
});
});