flash Actionscript 3 and php image upload

我的未来我决定 提交于 2019-12-13 04:39:50

问题


recently i am going through a project of badge-builder with action-script and flash.now i need some help for image uploading from the flash interface to the server and showing it back in the flash interface,

the back-end programing language is php and i am using action-scrip 3 and flash cs5

can anyone please give me a right direction how to achieve this job.

Thank you very much.


回答1:


Here is the AS3 code, it's just some quick and dirty timeline code:

var fileRef:FileReference = new FileReference();
fileRef.addEventListener( Event.SELECT, uploadFile );
fileRef.addEventListener( ProgressEvent.PROGRESS, fileUploadProgress );
fileRef.addEventListener( Event.COMPLETE, fileUploadComplete );

button.addEventListener( MouseEvent.CLICK, browseForFile );

function browseForFile( e:Event ):void
{
fileRef.browse();
}

function uploadFile( e:Event ):void
{
fileRef.upload( new URLRequest( "http://localhost/php5dev/test/upload_script.php"  ), "as3File", false );
}

function fileUploadProgress( e:ProgressEvent ):void
{
trace( ( e.bytesLoaded / e.bytesTotal ) * 100 );
}

function fileUploadComplete( e:Event ):void
{
trace( "upload complete" );
}

here is the PHP code:

<?php

$target = "uploads/" . basename( $_FILES[ "as3File" ][ "name" ] );

if ( move_uploaded_file( $_FILES[ "as3File" ][ "tmp_name" ], $target ) )
    echo( "file upload success<bt />" );
else
    echo( "error uploading file<br />" );

?>

Hope this helps, let me know if you need me to clarify anything.




回答2:


use the FileReference AS3 class to get a file into Flash, then use the FileReference.upload() method to send the file to a php script that will put the file on the server. Once that is done, do a URLRequest on the uploaded file to display it back in Flash. This is just the theory, I can add code if you need some help with that.




回答3:


yes yes its working still the product is in production mode just 2 nd day here is the link you can check

http://sunmicrosoft.com/badgebuilder/

thank you very much for you help



来源:https://stackoverflow.com/questions/3258845/flash-actionscript-3-and-php-image-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!