>백엔드 개발 >PHP 튜토리얼 >Flex+PHP实现上传图片|Flex+PHP Realization picture uploading

Flex+PHP实现上传图片|Flex+PHP Realization picture uploading

WBOY
WBOY원래의
2016-06-23 14:29:571005검색

1 Flex代码


 
    <script>                      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>        ]]>  <br>    </script> 
     
         
       
 
         
         
   
 

注:uploadURL.url = "http://localhost:80/ShowProduct-debug/uploadFile.php";路径一定要写对,否则回报Error #2044: 未处理的 IOErrorEvent:。 text=Error #2038: 文件 I/O 错误。
2. php代码

// Flash 传递的文件表单 name 属性为 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;   

?>

注:php文件一定要放到Apache运行的目录里,例如:把php文件放到C:\xampp\htdocs\ShowProduct-debug目录下

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.