Chciałem wysłać zaszyfrowany kod autoryzacji z Flash do PHP wraz z obrazkiem JPG. Nie nadaje się do umieszczania tego w zmiennych pobierania, więc obejrzałem go w ten sposób. Większość kodu to faktyczne gromadzenie migawki na scenie, ale tylko jej określony region. Częścią, która jest tutaj istotna, jest użycie writeMultiByte do zaszyfrowania zaszyfrowanego hasła na końcu informacji o obrazie jpb. Następnie wysyłam długość tego hasła przy użyciu ciągu url zmiennych get, tak aby PHP wiedział, że pokazuje dużo, aby odciąć koniec.
var stage_snapshot:BitmapData = new BitmapData(600, 120);
var myRectangle:Rectangle = new Rectangle(0, 0, 600, 120);
var myMatrix:Matrix = new Matrix();
var translateMatrix:Matrix = new Matrix();
translateMatrix.translate(-101, -33);
myMatrix.concat(translateMatrix);
stage_snapshot.draw(stage,myMatrix,null,null,myRectangle);
trace ("creating JPGEncoder");
// Setup the JPGEncoder, run the algorithm on the BitmapData, and retrieve the ByteArray
var encoded_jpg:JPGEncoder = new JPGEncoder(100);
var jpg_binary:ByteArray = new ByteArray();
jpg_binary = encoded_jpg.encode(stage_snapshot);
var pw = cryptoSalt.encrypt("mysecretpassword");
**var pwLength = pw.length;
jpg_binary.writeMultiByte(pw,"us-ascii");**
trace ("stage snapshot taken");
var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
var request:URLRequest = new URLRequest("savejpg.php?length1=" + pwLength);
request.requestHeaders.push(header);
request.method = URLRequestMethod.POST;
request.data = jpg_binary;
var loader:URLLoader = new URLLoader();
trace ("sending pic to php");
loader.load(request);
loader.addEventListener(Event.COMPLETE,finishSave);
PHP odbiorcza:
$pwlength = $_GET['length1'];
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
$pw = substr($jpg, - $pwlength);
$jpg = substr($jpg,0,strlen($jpg) - $pwlength);
$filename = 'uploads/test.jpg';
file_put_contents($filename, $jpg);
file_put_contents("uploads/pw.txt",$pw);
Dzięki! ... Nigdy wcześniej nie używałem Flex. Spróbuję. –