I have a simple PHP upload script that is called from my Flash App. I am sure it makes the call because it actually uploads the file!
我有一个简单的PHP上传脚本,可以从我的Flash App中调用。我确信它会调用它,因为它实际上传了文件!
session_start();
$default_path = 'files/';
$target_path = ($_POST['dir']) ? $_POST['dir'] : $default_path;
if(!file_exists($target_path)) mkdir($target_path, 0777, true);
$destination = $target_path . basename( $_FILES[ 'Filedata' ][ 'name' ] );
$file_name = rand(1,9999).$_FILES[ 'Filedata' ][ 'name' ];
if(move_uploaded_file($_FILES[ 'Filedata' ][ 'tmp_name' ], $destination)){
$_SESSION['path'] = 'flashuploader_online/upload/'.$destination;
}
However, I try to use the session variable "path" in another script but it gives me an empty value! Yes, I have made sure to use session_start.
但是,我尝试在另一个脚本中使用会话变量“path”,但它给了我一个空值!是的,我确保使用session_start。
Am I missing something?
我错过了什么吗?
Update
At least now I know what the problem is! But I am not sure how to solve it without it getting messy to pass across session variables. Any ideas?
至少现在我知道问题是什么!但我不知道如何解决它,如果没有它通过会话变量混乱。有任何想法吗?
2 个解决方案
#1
You are going to have to persist the session_id across all requests by passing it as a variable. I promise it won't get too messy! There are a couple changes you will need to make to the page that displays the flash as well as the script it posts to. You will also need to make a slight change to the Flash application itself, so that it can include the session ID when it uploads the file to the server.
您将不得不将session_id作为变量传递给所有请求。我保证不会太乱!您需要对显示Flash的页面以及它发布的脚本进行一些更改。您还需要对Flash应用程序本身稍作更改,以便在将文件上载到服务器时包含会话ID。
First, you will want to provide flash with the session ID by including it with FlashVars. You're going to need the page that is displaying the flash to be preprocessed with PHP, or it will not be possible to persist a session. Make sure you call session_start() in the page that outputs the Flash. You'll end up with something like this:
首先,您需要通过将Flash包含在FlashVars中来为flash提供会话ID。您将需要使用PHP预处理显示闪存的页面,否则将无法持久保存会话。确保在输出Flash的页面中调用session_start()。你最终会得到这样的东西:
<object classid="clsid:(blah)" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="800" height="800" id="ZoomifyHotspotViewer">
<param name="flashvars" value="phpsessionid=<? print session_id(); ?>">
<param name="src" value="YourSWF.swf">
<embed flashvars="phpsessionid=<? print session_id(); ?>" src="YourSWF.swf" pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash" width="800" height="800" name="YourSWF"></embed>
</object>
This part in particular is what needs to be added, in both the param and embed tags:
这部分特别是需要在param和embed标签中添加的内容:
phpsessionid=<? print session_id(); ?>
Then, in your Flash app when you make the request, you will now have access to the session id in the variable 'phpsessionid'. You need to include the value in the POST variable named PHPSESSID (all caps) - include it however you are including your other variables such as the 'dir' variable you make use of.
然后,在您发出请求的Flash应用程序中,您现在可以访问变量'phpsessionid'中的会话ID。您需要在POST变量中包含名为PHPSESSID(全部大写)的值 - 包括它,但是您要包含其他变量,例如您使用的'dir'变量。
Including that variable will ensure that when you call session_start() on the next page, the session will be restored instead of a new session being started. There are a couple configuration cases where this doesn't happen automatically. If that turns out to be the case for you (i.e. the session id is still different on the next page), you need to do the following in the page that processes the upload:
包含该变量将确保在下一页上调用session_start()时,将恢复会话而不是启动新会话。有几种配置情况不会自动发生。如果事实证明是这种情况(即下一页的会话ID仍然不同),则需要在处理上传的页面中执行以下操作:
session_id($_POST['PHPSESSID']);
session_start();
This will manually force PHP to renew the saved session with the specified ID. This shouldn't even be an issue you have to deal with, but if it is you may have to do something similar on the next page the user continues to as well, or add a general case to all pages:
这将手动强制PHP使用指定的ID续订已保存的会话。这甚至不应该是您必须处理的问题,但如果是,您可能必须在下一页上做类似的事情,用户继续,或者向所有页面添加一般情况:
if (isset($_REQUEST['PHPSESSID'])) {
session_id($_REQUEST['PHPSESSID']);
}
session_start();
Be sure that if you do end up needing to call session_id() in this way as a setter, that you do so before calling session_start().
确保如果你最终需要以这种方式调用session_id()作为setter,那么在调用session_start()之前就这样做了。
#2
Every time a web server provides you with a response ( a page, a graphic, etc. ) it has the opportunity to send your browser a cookie.
每次Web服务器为您提供响应(页面,图形等)时,它都有机会向您的浏览器发送cookie。
1) Each cookie is only sent back to the same web site as it came from in the first place 2) The "contents" of the cookie( the data it contains) can only be made up of whatever information the web server already knew anyway.
1)每个cookie只发送回到它首先来自同一个网站2)cookie的“内容”(它包含的数据)只能由Web服务器已经知道的任何信息组成。
So your browser automatically send cookies in "Cookie" variable in HTTP header. You can read it with folowing command in PHP:
因此,您的浏览器会自动在HTTP标头中的“Cookie”变量中发送Cookie。您可以使用PHP中的folowing命令来阅读它:
$headers = apache_request_headers();
echo $headers['Cookie'];
Server ( if session support enabled in PHP configuration ) automatically creates PHPSESSID ( you can modify variable name in configuration ) in a cookie and you can access it directly with above script ( you need to parse $headers in order to get PHPSESSID variable or any other cookie). I think there is no need to use flashvars, your browser automatically add Cookie variable in HTTP header.
服务器(如果在PHP配置中启用会话支持)会自动在cookie中创建PHPSESSID(您可以在配置中修改变量名称),并且您可以使用上面的脚本直接访问它(您需要解析$ headers以获取PHPSESSID变量或任何其他曲奇饼)。我认为没有必要使用flashvars,你的浏览器会自动在HTTP标头中添加Cookie变量。
Hope this helps !
希望这可以帮助 !
#1
You are going to have to persist the session_id across all requests by passing it as a variable. I promise it won't get too messy! There are a couple changes you will need to make to the page that displays the flash as well as the script it posts to. You will also need to make a slight change to the Flash application itself, so that it can include the session ID when it uploads the file to the server.
您将不得不将session_id作为变量传递给所有请求。我保证不会太乱!您需要对显示Flash的页面以及它发布的脚本进行一些更改。您还需要对Flash应用程序本身稍作更改,以便在将文件上载到服务器时包含会话ID。
First, you will want to provide flash with the session ID by including it with FlashVars. You're going to need the page that is displaying the flash to be preprocessed with PHP, or it will not be possible to persist a session. Make sure you call session_start() in the page that outputs the Flash. You'll end up with something like this:
首先,您需要通过将Flash包含在FlashVars中来为flash提供会话ID。您将需要使用PHP预处理显示闪存的页面,否则将无法持久保存会话。确保在输出Flash的页面中调用session_start()。你最终会得到这样的东西:
<object classid="clsid:(blah)" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="800" height="800" id="ZoomifyHotspotViewer">
<param name="flashvars" value="phpsessionid=<? print session_id(); ?>">
<param name="src" value="YourSWF.swf">
<embed flashvars="phpsessionid=<? print session_id(); ?>" src="YourSWF.swf" pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash" width="800" height="800" name="YourSWF"></embed>
</object>
This part in particular is what needs to be added, in both the param and embed tags:
这部分特别是需要在param和embed标签中添加的内容:
phpsessionid=<? print session_id(); ?>
Then, in your Flash app when you make the request, you will now have access to the session id in the variable 'phpsessionid'. You need to include the value in the POST variable named PHPSESSID (all caps) - include it however you are including your other variables such as the 'dir' variable you make use of.
然后,在您发出请求的Flash应用程序中,您现在可以访问变量'phpsessionid'中的会话ID。您需要在POST变量中包含名为PHPSESSID(全部大写)的值 - 包括它,但是您要包含其他变量,例如您使用的'dir'变量。
Including that variable will ensure that when you call session_start() on the next page, the session will be restored instead of a new session being started. There are a couple configuration cases where this doesn't happen automatically. If that turns out to be the case for you (i.e. the session id is still different on the next page), you need to do the following in the page that processes the upload:
包含该变量将确保在下一页上调用session_start()时,将恢复会话而不是启动新会话。有几种配置情况不会自动发生。如果事实证明是这种情况(即下一页的会话ID仍然不同),则需要在处理上传的页面中执行以下操作:
session_id($_POST['PHPSESSID']);
session_start();
This will manually force PHP to renew the saved session with the specified ID. This shouldn't even be an issue you have to deal with, but if it is you may have to do something similar on the next page the user continues to as well, or add a general case to all pages:
这将手动强制PHP使用指定的ID续订已保存的会话。这甚至不应该是您必须处理的问题,但如果是,您可能必须在下一页上做类似的事情,用户继续,或者向所有页面添加一般情况:
if (isset($_REQUEST['PHPSESSID'])) {
session_id($_REQUEST['PHPSESSID']);
}
session_start();
Be sure that if you do end up needing to call session_id() in this way as a setter, that you do so before calling session_start().
确保如果你最终需要以这种方式调用session_id()作为setter,那么在调用session_start()之前就这样做了。
#2
Every time a web server provides you with a response ( a page, a graphic, etc. ) it has the opportunity to send your browser a cookie.
每次Web服务器为您提供响应(页面,图形等)时,它都有机会向您的浏览器发送cookie。
1) Each cookie is only sent back to the same web site as it came from in the first place 2) The "contents" of the cookie( the data it contains) can only be made up of whatever information the web server already knew anyway.
1)每个cookie只发送回到它首先来自同一个网站2)cookie的“内容”(它包含的数据)只能由Web服务器已经知道的任何信息组成。
So your browser automatically send cookies in "Cookie" variable in HTTP header. You can read it with folowing command in PHP:
因此,您的浏览器会自动在HTTP标头中的“Cookie”变量中发送Cookie。您可以使用PHP中的folowing命令来阅读它:
$headers = apache_request_headers();
echo $headers['Cookie'];
Server ( if session support enabled in PHP configuration ) automatically creates PHPSESSID ( you can modify variable name in configuration ) in a cookie and you can access it directly with above script ( you need to parse $headers in order to get PHPSESSID variable or any other cookie). I think there is no need to use flashvars, your browser automatically add Cookie variable in HTTP header.
服务器(如果在PHP配置中启用会话支持)会自动在cookie中创建PHPSESSID(您可以在配置中修改变量名称),并且您可以使用上面的脚本直接访问它(您需要解析$ headers以获取PHPSESSID变量或任何其他曲奇饼)。我认为没有必要使用flashvars,你的浏览器会自动在HTTP标头中添加Cookie变量。
Hope this helps !
希望这可以帮助 !