swfupload 302 error

只愿长相守 提交于 2019-12-03 17:15:28

The default PHP session handler mechanism uses both your Cookie and your User-Agent to match a session to a user. As Flash identifies itself to the server with the user-agent of "ShockWave Flash", which is different than your browser's UA, php assigns a new session to the request.

You can check this if you output _POST data and then compare those values with the ones you get after session_start() or if you change your browser UA to exactly match that sent by Flash.

The solution?

Pass the session ID to the server whatever way you want, the default being _POST, and initialize the session with the correct id.

SWFUpload provides you with post_params that "defines the name/value pairs that will be posted with each uploaded file".

// SWFUpload example - taken from you own config file
post_params : {
    "sid" : sid => THIS WOULD BE YOUR SESSION ID!; you can put <?=session_id()?>
},

And then on the server side...

// Prior to starting the session as you normally do you'll want to check if 
// you're trying to pass a session id by post, if so, initialize session with it
<?php
if(isset($_POST['sid']))
{
    session_id($_POST["sid"]);
}
session_start();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!