gpt4 book ai didi

javascript - swfupload 302错误

转载 作者:行者123 更新时间:2023-11-29 10:21:39 26 4
gpt4 key购买 nike

所以我有这个用于将 swfuploader 加载到页面上的 javascript 代码 (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")
}
});

但是每当我使用 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; 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

最终状态为 302 并重定向到登录页面....

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

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

其次,如何将其转换为最顶层的 javascript SWFUpload 代码,以便浏览器中的实际 swfuploader 能够适当修复其 Cookie 请求....

最佳答案

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

如果您输出 _POST 数据,然后将这些值与您在 session_start() 之后获得的值进行比较,或者如果您将浏览器 UA 更改为完全匹配,则可以检查此项由 Flash 发送。

解决方案?

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

SWFUpload 为您提供了“defines the name/value pairs that will be posted with each uploaded file”的post_params

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

然后在服务器端...

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

关于javascript - swfupload 302错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10488110/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com