Flex + PHP uploads images | Flex + PHPRealizationpictureuploading

Source: Internet
Author: User
Flex + PHP uploads images | Flex + PHPRealizationpictureuploading 1 Flex code



<br /> import flash.net.FileReference; <br /> import mx.controls.Alert; <br /> import mx.events.CloseEvent; <br /> import flash.events.*; <br /> private var file : FileReference; <br /> private var uploadURL : URLRequest; <br /> private function init() : void{ <br /> Security.allowDomain("*"); <br /> file = new FileReference(); <br /> file.addEventListener(ProgressEvent.PROGRESS, onProgress); <br /> file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUPLOAD_COMPLETE_DATA); <br /> file.addEventListener(Event.SELECT, onSelect); <br /> uploadURL = new URLRequest(); <br /> uploadURL.url = "http://localhost:80/ShowProduct-debug/uploadFile.php"; <br /> uploadURL.method = "post"; <br /> } <br /> private function upload() : void{ <br /> var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png"); <br /> var allTypes:Array = new Array(imageTypes); <br /> file.browse(allTypes); <br /> } <br /> private function onSelect(e : Event) : void{ <br /> Alert.show("上传 " + file.name + " (共 "+Math.round(file.size)+" 字节)?", "确认上传",Alert.YES|Alert.NO,null,proceedWithUpload); <br /> } <br /> private function onProgress(e:ProgressEvent) : void{ <br /> lbProgress.text = " 已上传 " + e.bytesLoaded + " 字节,共 " + e.bytesTotal + " 字节"; <br /> } <br /> private function proceedWithUpload(e : CloseEvent) : void{ <br /> if (e.detail == Alert.YES){ <br /> file.upload(uploadURL); <br /> } <br /> } <br /> private function onUPLOAD_COMPLETE_DATA(evt:DataEvent):void <br /> { <br /> Alert.show(evt.data.toString()); <br /> } <br />







Note: uploadURL. url = "http: // localhost: 80/ShowProduct-debug/uploadFile. php "; the path must be correct; otherwise, Error #2044 is returned: unprocessed IOErrorEvent :. Text = Error #2038: file I/O Error.
2. php code

// The name attribute of the file Form passed by Flash is Filedata
$ FileName = $ _ FILES ["Filedata"] ["name"];
$ File = $ _ FILES ["Filedata"] ["tmp_name"];
$ Path = "uploadFiles /";
If (! Is_dir ("./uploadFiles ")){
@ Mkdir ("./uploadFiles ");
}
If (move_uploaded_file ($ file, $ path. $ fileName )){
Echo Success;
} Else {
Echo Fail;
}
?>

Note: The php file must be placed in the directory where Apache runs. for example, put the php file in the C: \ xampp \ htdocs \ ShowProduct-debug directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.