swfupload 302错误 [英] swfupload 302 error

查看:204
本文介绍了swfupload 302错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个javascript代码将swfuploader加载到页面上( http://code.google。 com / p / swfupload /

  swfuPubThumbnailUploader = new SWFUpload({
upload_url:/ upload_thumbnail ,
flash_url:/Flash/swfupload.swf,
FILE_SIZE_LIMIT:512 +MB,
file_post_name,注意:文件[SWF]',
FILE_TYPES:* 。.JPG; * JPEG,GIF *; * PNG',
file_types_description:图像文件,
file_queue_limit:1,
button_placeholder_id:SWF反式文件选择器 ,
button_text:'',
button_image_url:'',
button_width:85,
button_height:25,
button_cursor:SWFUpload.C​​URSOR.HAND ,
button_window_mode:SWFUpload.WINDOW_MODE.TRANSPARENT,

post_params:{
SID:SID
},

preserve_relative_urls:真,
file_queued_handler:fileQueued,
file_queue_error_handler:fileQueueError,
file_dialog_complete_handler:fileDialogComplete,
file_dialog_start_handler:sLibraryFileDialogStart,
upload_start_handler:sLibraryPubUploadStart,
upload_progress_handler:sLibraryPubUploadProgress,
upload_error_handler:sLibraryPubUploadError,
upload_success_handler:sLibraryPubUploadSuccess,
upload_complete_handler:sLibraryPubUploadComplete,
queue_complete_handler:queueComplete,//队列插件事件

custom_settings:{
progressTarget:(fsPPUploadProgress)
}
});

但是当我上传(上传图片,更具体...)使用swfuploader,swfuploader会抱怨302错误,这表明url正在重定向...但是当我访问上传url'/ upload_thumbnail'没有重定向发生和上传url加载好...所以我检出了fiddler检查两个情况



当我通过浏览器访问/ upload_thumbnail时:

  GET / upload_thumbnail HTTP / 1.1 
Host:my.domain.com
User-Agent:Mozilla / 5.0(Windows NT 6.1; WOW64; rv:12.0)Gecko / 20100101 Firefox / 12.0
Accept:text / html,application / xhtml + xml,application / xml; q = 0.9,* / *; q = 0.8
Accept-Language:en-us,en; q = 0.5
Accept-Encoding:gzip,deflate
Connection:keep-alive
Cookie:__utma = 171146939.260757561.1311084520.1336078159.1336400574.117; __utmz = 171146939.1311084520.1.1.utmcsr =(direct)| utmccn =(direct)| utmcmd =(none); __utma = 104299925.1228643063.1313075490.1335542105.1335567483.41; __utmz = 104299925.1333981938.38.25.utmcsr = my.domain.com:8090 | utmccn =(referral)| utmcmd = referral | utmcct = / browse / MD-2760; __qca = P0-29539114-1325619242917; SESS5ccc5f20cb72179af2f569e77eaa49da = 6vde0rln7q3384k5lcvedsgfh3; SimpleSAMLAuthToken = _c2f653a6e9b18b10439d73849fb1142a7d43851998; __utmc = 171146939; has_js = 1
If-Modified-Since:Mon,07 May 2012 19:13:38 +0000
If-None-Match:1336418018

使用状态200加载正常



然后swfuploader

  POST / upload_thumbnail HTTP / 1.1 
Accept:text / *
Content-Type:multipart / form-data;边界= ---------- gL6Ef1Ef1KM7Ij5gL6ae0gL6GI3GI3
的User-Agent:的Shockwave Flash
主机:my.domain.com
的Content-Length:847357
连接:保持-Alive
Pragma:no-cache
Cookie:__utma = 171146939.1934231828.1323362429.1328283903.1333582993.5; __utmz = 171146939.1323362429.1.1.utmcsr =(direct)| utmccn =(direct)| utmcmd =(none); __utma = 104299925.1653270920.1323362234.1334760245.1335992862.7; __utmz = 104299925.1323362234.1.1.utmcsr =(direct)| utmccn =(direct)| utmcmd =(none); SESS5ccc5f20cb72179af2f569e77eaa49da = 0qjn1gva2rhlcqiqp2g7liumd0; __qca = P0-1855943596-1327334275533

它以状态302结束并重定向到登录页面。 ..



所以我发现,罪魁祸首是Cookie:request ....如果我将浏览器的COOKIE请求切换到swfuploader的Cookie请求,swfuploader请求将加载正确状态为200 ...



我的第一个问题是...为什么? swfuploader的Cookie请求有什么问题?



其次,如何将其转换为最上层的JavaScript SWFUpload代码,使得浏览器中的实际swfuploader将具有Cookie请求固定正确....

解决方案

默认的 PHP会话处理程序机制 strong> Cookie和您的用户代理,以便将会话与用户进行匹配。由于Flash使用与您的浏览器的UA不同的ShockWave Flash用户代理向服务器标识自己,因此php会为该请求分配一个新会话。



如果输出 _POST 数据,然后将这些值与在 session_start()或如果您将浏览器的UA更改为与Flash发送的完全匹配。



解决方案

将会话ID以任何方式传递给服务器,默认值为 _POST ,并使用正确的ID初始化会话。



SWFUpload为您提供 post_params 定义将与每个上传的文件一起发布的名称/值对

  // SWF上传示例 - 取自您自己的配置文件
post_params:{
sid:sid =>这将是你的会议ID!你可以把<?= session_id()?>
},

然后在服务器端...

  //在通常情况下启动会话之前,您需要检查
//是否尝试传递会话id by post,如果是,初始化会话
<?php
if(isset($ _ POST ['sid']))
{
session_id($ _ POST [ sid]);
}
session_start();


so I have this javascript code for loading swfuploader onto a page ( http://code.google.com/p/swfupload/)

swfuPubThumbnailUploader = new SWFUpload({
  upload_url : "/upload_thumbnail",
  flash_url : "/Flash/swfupload.swf",
  file_size_limit : 512 + " MB",
  file_post_name: 'files[swf]',
  file_types : '*.jpg;*.jpeg;*.gif;*.png',
  file_types_description: "Image Files",
  file_queue_limit : 1,
  button_placeholder_id: 'swf-trans-file-selector',
  button_text: '',
  button_image_url: '',
  button_width: "85",
  button_height: "25",
  button_cursor : SWFUpload.CURSOR.HAND,
  button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,

  post_params : {
                "sid" : sid
  },

  preserve_relative_urls : true,
  file_queued_handler : fileQueued,
  file_queue_error_handler : fileQueueError,
  file_dialog_complete_handler : fileDialogComplete,
  file_dialog_start_handler : sLibraryFileDialogStart,
  upload_start_handler : sLibraryPubUploadStart,
  upload_progress_handler : sLibraryPubUploadProgress,
  upload_error_handler : sLibraryPubUploadError,
  upload_success_handler : sLibraryPubUploadSuccess,
  upload_complete_handler : sLibraryPubUploadComplete,
  queue_complete_handler : queueComplete, // Queue plugin event

  custom_settings: {
    progressTarget : ("fsPPUploadProgress")
  }
});

but then whenever I upload (upload images, to be more specific...) using swfuploader, swfuploader will complain about 302 error which suggest that the url is redirecting...but then when I visited the upload url '/upload_thumbnail' no redirection takes place and the upload url loaded fine...so I checked out fiddler to check the two cases and here are the requests for each of the case

For when I visited /upload_thumbnail via browser:

GET /upload_thumbnail HTTP/1.1
Host: my.domain.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: __utma=171146939.260757561.1311084520.1336078159.1336400574.117; __utmz=171146939.1311084520.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=104299925.1228643063.1313075490.1335542105.1335567483.41; __utmz=104299925.1333981938.38.25.utmcsr=my.domain.com:8090|utmccn=(referral)|utmcmd=referral|utmcct=/browse/MD-2760; __qca=P0-29539114-1325619242917; SESS5ccc5f20cb72179af2f569e77eaa49da=6vde0rln7q3384k5lcvedsgfh3; SimpleSAMLAuthToken=_c2f653a6e9b18b10439d73849fb1142a7d43851998; __utmc=171146939; has_js=1
If-Modified-Since: Mon, 07 May 2012 19:13:38 +0000
If-None-Match: "1336418018"

Which loads fine with status 200

Then the one from swfuploader

POST /upload_thumbnail HTTP/1.1
Accept: text/*
Content-Type: multipart/form-data; boundary=----------gL6Ef1Ef1KM7Ij5gL6ae0gL6GI3GI3
User-Agent: Shockwave Flash
Host: my.domain.com
Content-Length: 847357
Connection: Keep-Alive
Pragma: no-cache
Cookie: __utma=171146939.1934231828.1323362429.1328283903.1333582993.5; __utmz=171146939.1323362429.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=104299925.1653270920.1323362234.1334760245.1335992862.7; __utmz=104299925.1323362234.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); SESS5ccc5f20cb72179af2f569e77eaa49da=0qjn1gva2rhlcqiqp2g7liumd0; __qca=P0-1855943596-1327334275533

which ended up with status 302 and redirection to a login page....

So I found out that the culprit is the Cookie: request....if I switch the browser's COOKIE request to the swfuploader's Cookie request the swfuploader request would load with status 200 properly...

My first question is.....WHY? What's wrong with the swfuploader's Cookie request?

And secondly, how can this be translated to my javascript SWFUpload code at the topmost such that the actual swfuploader in the browser will have its Cookie request fixed appropriately....

解决方案

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();

这篇关于swfupload 302错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆