论坛首页 入门技术论坛

Flex 2和PHP上传文件

浏览 5861 次
该帖已经被评为新手帖
作者 正文
   发表时间:2006-10-26  
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init();" width="200" height="150">
	<mx:Script>
		<![CDATA[
			import flash.net.FileReference;
			import mx.controls.Alert;
			import mx.events.CloseEvent;
			import flash.events.*;
						
			private var file : FileReference;
			private var uploadURL : URLRequest;
            
			private function init() : void{
				Security.allowDomain("*"); 
				file = new FileReference(); 
				file.addEventListener(ProgressEvent.PROGRESS, onProgress); 
				file.addEventListener(Event.SELECT, onSelect);
				uploadURL = new URLRequest(); 
				uploadURL.url = "http://localhost:8081/upload.php"; 
			}
			
			private function upload() : void{
				var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
				var allTypes:Array = new Array(imageTypes);
				file.browse(allTypes);
			}
			
			private function onSelect(e : Event) : void{
				Alert.show("上传 " + file.name + " (共 "+Math.round(file.size)+" 字节)?",	"确认上传",Alert.YES|Alert.NO,null,proceedWithUpload);
			}
			
			private function onProgress(e:ProgressEvent) : void{
				lbProgress.text = " 已上传 " + e.bytesLoaded + " 字节,共 " + e.bytesTotal + " 字节";
			}
			
			private function proceedWithUpload(e : CloseEvent) : void{
				if (e.detail == Alert.YES){
 					file.upload(uploadURL);
				}
			}
		]]>
	</mx:Script>
	
	<mx:Canvas width="100%" height="100%">
		<mx:VBox width="100%" horizontalAlign="center">
		</mx:VBox>
		<mx:Button label="上传文件" click="upload();" y="91"/>
		<mx:Label id="lbProgress" text="上传" x="87.5" y="26"/>
	</mx:Canvas>


</mx:Application>


<!-- saved from url=(0014)about:internet -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upload</title>
<body scroll="no">

  	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fileupload" width="200" height="150"
			codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
			<param name="movie" value="fileupload.swf" />
			<param name="quality" value="high" />
			<param name="bgcolor" value="#869ca7" />
			<param name="allowScriptAccess" value="sameDomain" />
			<embed src="fileupload.swf" quality="high" bgcolor="#869ca7"
				width="200" height="150" name="fileupload" align="middle"
				play="true"
				loop="false"
				quality="high"
				allowScriptAccess="sameDomain"
				type="application/x-shockwave-flash"
				pluginspage="http://www.adobe.com/go/getflashplayer">
			</embed>
	</object>

</body>
</html>


<?php  
// Flash 传递的文件表单 name 属性为 Filedata  
$fileName = $_FILES["Filedata"]["name"];  
$file = $_FILES["Filedata"]["tmp_name"];  
$path = "uploadFiles/";  
if (move_uploaded_file($file, $path . $fileName)){  
 echo 1;  
}else{  
 echo 0;  
}
?>
   发表时间:2006-11-09  
图片没上传到UPLOADFILES下,是咱回事呢,,我把相应路径都该了的
请问????????
0 请登录后投票
   发表时间:2006-11-10  
我用的是appserv的环境,flash和php文件都放在根目录下的。是测试没有问题的代码才发出来的。你的目录名字是全大写的还是和变量名一样的大小写混合的?
0 请登录后投票
   发表时间:2006-11-10  
---+flex--
        --uploadFiles(上传的文件夹)
        --fileupload.mxml
        --fileupload.swf
        --upload.php
        --upfile.htm

*文件结构就是这样的,谢谢你的回复!
0 请登录后投票
   发表时间:2006-11-10  
没有提示。。。
if (move_uploaded_file($file, $path . $fileName)){    
echo 1;    
}else{    
echo 0;    
}  
0 请登录后投票
   发表时间:2006-11-10  
uploadURL.url = "http://localhost:8081/upload.php";   

这个是我本地测试环境的端口号,跟你的测试环境匹配么?
0 请登录后投票
   发表时间:2006-11-10  
我刚刚修改了那个url的地址,然后部署到公网的服务器上经过测试代码没有问题。
0 请登录后投票
   发表时间:2006-11-13  
我直接是‘http://192.168.0.131/upload.php’
用的是IIS服务器,是没有端口号的,我在这个地址下访问其他的网页都是可以的,,,

;;;;?????那会不会是其他什么问题呢,?望帮助,谢谢!
0 请登录后投票
   发表时间:2006-11-13  
没有遇到过,你装个wamp或者xampp或者appserv试试。
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics