2011-03-24 4 views
0

Flash에서 영화 클립의 '스크린 샷'을 가져 와서 AS Core Lib JPGEncoder 클래스를 사용하여 Jpg로 인코딩 한 다음 POST로 결과 ByteArray를 PHP로 제출하려고합니다. 이미지를 MIME로 인코딩 된 전자 메일에 포함시킵니다.BitmapData from Flash -> PHP ->

현재 Flash에서 인코딩 된 ByteArray를 저장 했으므로 문제가 없으므로 Flash에서 PHP로 전송하는 것이 문제입니다. SwiftMailer를 사용하여 jpeg를 첨부 파일로 사용하여 복잡한 이메일을 보내고 있습니다. 현재 스크립트는 전송 된 데이터에서 첨부 파일을 작성하는 시점에서 충돌하는 것 같습니다.

trace("Sending Email"); 
    var rootMC:MovieClip = MovieClip(root); 
    var data1:BitmapData = new BitmapData(rootMC.width, rootMC.height); 
    data1.draw(rootMC); 

    var en:JPGEncoder = new JPGEncoder(80); 
    var bArray:ByteArray= en.encode(data1); 

var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream"); 

    var request:URLRequest = new URLRequest(); 
    request.requestHeaders.push(header); 
    request.url = mailLoc;//MailLoc is the URL of the PHP. 
    request.method = URLRequestMethod.POST; 
    request.data = bArray; 
    var loader:URLLoader = new URLLoader(); 
    loader.dataFormat = URLLoaderDataFormat.BINARY; 
    loader.addEventListener(Event.COMPLETE, MailCompleteHandler); 
    try 
    { 
     loader.load(request); 
    } 
    catch(error:Error) 
    { 
     trace("Unable to load URL"); 
    } 

을 그리고 여기에 PHP입니다 :

는 여기에 액션 스크립트의

require_once 'lib/swift_required.php'; 
$image = file_get_contents("php://input"); 
$attachment = SwiftAttachment::newInstance($image, 'submission.jpg', 'image/jpg');//<--This line stuffs it 

$message = Swift_Message::newInstance() 
    /*Give the message a subject*/ 
    ->setSubject('Your subject') 
    /*Set the from address with an associative array*/ 
    ->setFrom(array('[email protected]'=>'Battle for Brisbane')) 
    /*Set the to addresses with an associative array*/ 
    ->setTo(array('[email protected]')) 
    /*Give it a body*/ 
    ->setBody('Congratulations! You submission to Battle for Brisbane was received'); 
    $message->attach($attachment);//<--When the attachment above is commented out, so is this 

    $transport = Swift_SendmailTransport::newInstance(); 
    $mailer = Swift_Mailer::newInstance($transport); 
    $mailer->send($message); 

이 전문 작업, 그래서 어떤 도움을 크게 감상 할 수있다.

업데이트 : SwiftAttachment가 아니라 Swift_Attachment입니다. 누락 된 밑줄, 문제 해결, 응용 프로그램 기능. 이 문제를 도와 주신 모든 분께 감사드립니다.

+0

이것은 [어제 귀하의 질문의 정확한 중복] 것으로 보입니다 (http://stackoverflow.com/questions/5399235/bitmapdata-from-flash-to-php-to-email). 나는 여전히 1x1 GIF의 원시 출력을보고 싶지만, 여기 저기에 있지만. – Charles

+0

어제의 세련된 버전입니다. 사소한 문제 중 일부는 스스로 해결되었습니다 (수동으로 인코딩하는 대신 SwiftMailer 사용). 그러나 큰 문제는 끝나지 않았습니다. 1x1 픽셀의 관점에서, Flash-> PHP에서 보내는 모든 데이터는 쓰기 (fwrite) 또는 마임 첨부를 거부합니다. –

+0

'$ image'는'strlen'을 가지고 있습니까? – Charles

답변

0

Swift_Attachment에서 밑줄 표시가 누락되었다고 생각됩니다. 그거 싫어하지 않아?

+0

바로 그거야. 그러나 적절한 "디버그"방법론을 사용하면 문제가되는 코드를 쉽게 분리 할 수있었습니다. 기본적으로 모든 것을 작은 작업으로 나누고 하나를 테스트 한 다음 위에 다음 작업을 만듭니다. 현재 작업이 실패하면 초점을 맞출 수있는 위치를 알 수 있습니다. – goliatone

2

인코딩 된 이미지가 유효한지 확인 했습니까?

로컬 서버 또는 다른 서버가있는 경우 사용해보십시오.

또한 이미지 하나를 플래시로로드하여 서버로 보내고 생성 된 이미지를 보내는 대신 작동하는지 확인할 수 있습니다.

플래시에서 이미지를 전송하는 방법에 관해서는,이

var request:URLRequest = new URLRequest(mailLoc); 
request.contentType = 'application/octet-stream'; 
request.method = URLRequestMethod.POST; 
request.data = bArray; 

var loader:URLLoader = new URLLoader(); 
loader.addEventListener(Event.COMPLETE, MailCompleteHandler); 
loader.addEventListener(IOErrorEvent.IO_ERROR, _onImageError); 
try 
{ 
    loader.load(request); 
} 
catch(error:Error) 
{ 
    trace("Unable to load URL"); 
} 


private function _onImageError(e:IOErrorEvent):void { 
    trace("IOErrorEvent: ",e.type," : ",e.text) 
} 

을 시도하고 PHP 스크립트를 들어, 파일을 저장하기 위해 처음 시도 할 수 있습니다.

//bindary data. 
$image_bytes = $GLOBALS["HTTP_RAW_POST_DATA"]; 
//change to whatever works for you 
$file_name = "testfile.jpg"; 
$file_path = "../uploads/$file_name"; 

$file = fopen($file_path, 'w+'); 

if (!fwrite($file, $image_bytes)) { 
    return "Error writing to file: $file"; 
} 

fclose($file); 
+0

그 goliatone 주셔서 감사. 나는 당신이 제안한 변화를했다. 플래시 종료시 IO 문제에 대한 플래그가 생성되지 않습니다. 어떤 이유로 PHP 스크립트는 파일을 작성하지 않습니다. 이상한 ... –

+0

다른 PHP 설정을 시도 했습니까? 아니면 이전에 업로드 한 이미지 대신 생성 된 이미지를 전송 하시겠습니까? – goliatone