Tôi muốn gửi biểu mẫu mã ủy quyền được mã hóa Flash tới PHP cùng với hình ảnh JPG. Nó không phù hợp để đăng bài này trong các biến nhận được và vì vậy tôi đã nhận được xung quanh nó theo cách này. Hầu hết các mã là thu thập thực tế của một ảnh chụp màn hình sân khấu, nhưng chỉ một khu vực cụ thể của nó. Phần có liên quan đến ở đây là việc sử dụng writeMultiByte để gắn vào mật khẩu được mã hóa vào cuối thông tin hình ảnh jpb. Sau đó tôi gửi chiều dài của mật khẩu này bằng cách sử dụng chuỗi url biến get để PHP biết hiển thị nhiều để cắt bỏ phần cuối.
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);
Các nhận PHP:
$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);
Cảm ơn! ... Tôi chưa từng sử dụng Flex trước đây. Tôi sẽ thử. –