由于我的AS3和Php / Java知识不好,我遇到了这个问题。
我有一个AS3函数将位图数据发送到PHP文件以保存一些图像,在这个函数中我还添加了一些其他参数,新参数应该给我一个我需要的字符串值。
private function saveImageForFacebook(evt:MouseEvent)
// Sends the Bitmap data to php
{
var bitmapData:BitmapData=new BitmapData(wheelCanvas.width, wheelCanvas.height);
bitmapData.draw(wheelCanvas);
var jpgEncoder:JPGEncoder = new JPGEncoder(80);
var byteArray:ByteArray = jpgEncoder.encode(bitmapData);
var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest ("http://www.someurl.com/flash-test/saveimg.php");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = byteArray;
navigateToURL(jpgURLRequest, "_blank");
// Creates the string value that I need to use in saveimg.php
var suffixUrl:String = "";
for(var i:int=0; i < customizedColorArr.length; i++)
{
if(customizedColorArr[i] != "")
{
suffixUrl += "&" + customizedPartValueArr[i] + "=" + customizedColorArr[i];
}
}
suffixUrl = wheelName + "&variant_name=" + variantName + suffixUrl;
trace(suffixUrl);
}
不知怎的,我需要在saveimg.php文件中跟踪“suffixUrl”值,但我不知道如何。
这是我的php文件的外观以及suffixUrl需要去的地方。
<?php
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
$uniqueStamp = date(U);
//$filename = "temp_image.jpg";
$filename = $uniqueStamp . ".jpg";
$fp = fopen( $filename,"wb");
$result = fwrite( $fp, $GLOBALS[ 'HTTP_RAW_POST_DATA' ] );
fclose( $fp );
}
?>
<meta property="og:image" content="http://www.someurl.com/flash-test/src_server/<?php echo $filename ; ?>" />
<SCRIPT LANGUAGE="JavaScript">
function redirect () {
window.location.href = "http://www.facebook.com/sharer.php?u=http://www.someurl/flash-test/Main3D.html?"+suffixUrl, '_self';
}
</SCRIPT>
<BODY onload="redirect()">
您将在我的javascript函数中看到“suffixUrl”。这就是我试图控制这个价值的地方。
答案 0 :(得分:0)
假设您的“php文件”是嵌入Flash的文件,您可以使用ExternalInterface从Flash调用redirect
函数。
Flash:
ExternalInterface.call("redirect", suffixUrl);
注意:您需要导入flash.external.ExternalInterface;
JavaScript:
function redirect (suffixUrl) {
window.location.href = "http://www.facebook.com/sharer.php?u=http://www.someurl/flash-test/Main3D.html?" + suffixUrl;
}
答案 1 :(得分:0)
您不希望将变量发送到 Javascript ;您想将变量发送到 PHP 。
将后缀生成代码块移动到位图发送部分上方,然后更改此行。
var jpgURLRequest:URLRequest = new URLRequest ("http://www.someurl.com/flash-test/saveimg.php?suffixUrl=" + suffixUrl);
然后,在 PHP
中window.location.href = "http://www.facebook.com/sharer.php?u=http://www.someurl/flash-test/Main3D.html?" + <?php echo $_GET['suffixUrl'] ?>, '_self';
这会有效,但您还必须清理 安全的输入。