آپلود فایل توسط فلش

با عرض سلام!
سالروز رحلت حاج احمد خمینی (ره) رو به همگی تسلیت عرض میکنم.

آقا کسی میدون چطور میشه توسط فلش فایلهایی مثل عکس رو آپلود کرد؟
ممنون!
 

kiarash.M

Active Member
من تو as2 یه نمونه درست کرده بودم :


کلاس upload :
PHP:
/*----------------------------------------------------
Copyright 2007 © Kiafilm Inc rights reserved
Version: 1.0

Author:
	Kiarash.M 
	[email protected]
-----------------------------------------------------*/
import flash.net.FileReference;
class upload {





	function upload() {
		trace("hi class ;) halet chetore :d to sazandat karii bahat nadaram :P");
	}
 
	function setAction(level:Number) {


		_root["f"+level]["browse_btn_"+level].enabled = true;

		var listener:Object = new Object();
		listener.onSelect = function(selectedFile:FileReference):Void  {
			selectedFile.upload("upload.php");
		};
		listener.onHTTPError = function(file:FileReference, httpError:Number):Void  {
			_root["f"+level]["loader_1"].contentPath = "error";
			_root["f"+level]["loader_1"].content.errorMSG.text = "HTTPError number: "+httpError+"\nFile: "+file.name;
		};




		listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void  {
			_root["f"+level].pb_.setProgress(bytesLoaded,bytesTotal);
			//_root["f"+level]["deatile_"+level].text += ("onProgress: "+file.name+" with bytesLoaded: "+bytesLoaded+" bytesTotal: "+bytesTotal);
		};



		listener.onIOError = function(file:FileReference):Void  {
			_root["f"+level]["loader_1"].contentPath = "error";
			_root["f"+level]["loader_1"].content.errorMSG.text = "IOError: "+file.name;
		};

		listener.onSecurityError = function(file:FileReference, errorString:String):Void  {
			_root["f"+level]["loader_1"].contentPath = "error";
			//_root["f"+level]["loader_"+level].content.errorMSG.text = "SecurityError: "+SecurityError+"\nFile: "+file.name;
		};
		listener.onComplete = function(selectedFile:FileReference):Void  {
			_root["f"+level]["deatile_1"].text = "";
			for (var i in selectedFile) {
				_root["f"+level]["deatile_1"].text += "<b>"+i+":</b> "+selectedFile[i]+"\n";
			}
			downloadImage(selectedFile.name);
			_root.ssl.text += selectedFile.name+"/";
		};

		var imageFile:FileReference = new FileReference();
		imageFile.addListener(listener);

		_root["f"+level].browse_btn.onPress = uploadImage;
		_root["f"+level]["loader_"+level].addEventListener("complete",imageDownloaded);


		function uploadImage(event:Object):Void {
			imageFile.browse([{description:"Image Files", extension:"*.jpg;*.gif;*.png"}]);
		}

		function imageDownloaded(event:Object):Void {
			if (event.total == -1) {
				_root["f"+level]["loader_1"].contentPath = "error";
			}
		}

		function downloadImage(file:Object):Void {
			_root["f"+level]["loader_1"].contentPath = "./files/"+file;
		}
	}


}

محتوایات fla که فقط با کد ها کامپوننت ها رو ساختم :



PHP:
_global.style.setStyle("fontFamily","Tahoma");
_global.style.setStyle("fontSize",11);



import mx.controls.Alert;
import mx.controls.*;
import mx.containers.*;
import upload;

this.createClassObject(Accordion,"main_form",3,{_x:27, _y:150});//165
main_form.setSize(430,270);

code = 1;


_root["f"+code] = main_form.createChild(mx.core.View, "library_tree", {label:"1."});
_root["f"+code].createClassObject(Button,"browse_btn",300,{_x:350, _y:10, _width:65, _height:20, label:"Browse"});
_root["f"+code].createClassObject(TextInput,"tx_input_1",301,{_x:10, _y:10, _width:330, _height:20});
_root["f"+code].createClassObject(Button,"upload_btn",302,{_x:350, _y:35, _width:65, _height:20, label:"Upload"});
_root["f"+code].createClassObject(ProgressBar,"pb_",333,{_x:10, _y:35, _width:330});
_root["f"+code].pb_.mode = "manual";
_root["f"+code].pb_.label = "%1 out of %2 Uploaded";
_root["f"+code].createClassObject(Label,"label_1",303,{_x:365, _y:65, text:"نوع قالب"});
_root["f"+code].createClassObject(ComboBox,"com_1",304,{_x:270, _y:65, _width:70});
_root["f"+code].com_1.addItem({label:"معمولي", fs:"mamoli"});
_root["f"+code].com_1.addItem({label:"چندتکه", fs:"chandTekE"});
_root["f"+code].createClassObject(Label,"label_2",305,{_x:215, _y:65, text:"سايز چاپ"});
_root["f"+code].createClassObject(ComboBox,"com_2",306,{_x:150, _y:65, _width:65});
_root["f"+code].com_2.addItem({label:"13*18"});
_root["f"+code].createClassObject(Label,"label_3",307,{_x:110, _y:65, text:"تعداد"});
_root["f"+code].createClassObject(NumericStepper,"num_1",308,{_x:40, _y:65, _width:65});
_root["f"+code].num_1.maximum = 100;
_root["f"+code].createClassObject(Label,"label_4",309,{_x:365, _y:95, text:"برش"});
_root["f"+code].createClassObject(ComboBox,"com_4",310,{_x:210, _y:95, _width:130});
_root["f"+code].createClassObject(Label,"label_5",311,{_x:170, _y:95, text:"رنگ"});
_root["f"+code].com_4.addItem({label:"13*18"});
_root["f"+code].createClassObject(ComboBox,"com_5",312,{_x:100, _y:95, _width:65});
_root["f"+code].com_5.addItem({label:"13*18" , data:"sefid"});
_root["f"+code].com_5.addItem({label:"13*18" , data:"siah"});
_root["f"+code].createClassObject(TextArea,"deatile_1",313,{_x:10, _y:125, _width:265, _height:110, html:true});
_root["f"+code].createClassObject(Loader,"loader_1",314,{_x:280, _y:125, _width:130, _height:105, scaleContent:true, contentPath:"uploadPRV.jpg"});

_root["f"+code].upload_btn_1.enabled = false;
var setAS_1 = new upload();
setAS_1.setAction(1);
//********************************************************
System.security.allowDomain("http://localhost/");//*******
//********************************************************
this.generate_btn.onRelease = function() {
	this.enabled = false;

	for (ci=300, i=0; i<(NM_.value-1); i++, ci += 10) {
		var code:Number = Number(i+2);

		_root["f"+code] = main_form.createChild(mx.core.View, "library_tree"+code, {label:code+"."});

		_root["f"+code].createClassObject(Button,"browse_btn",300,{_x:350, _y:10, _width:65, _height:20, label:"Browse"});
		_root["f"+code].createClassObject(TextInput,"tx_input_1",301,{_x:10, _y:10, _width:330, _height:20});
		_root["f"+code].createClassObject(Button,"upload_btn",302,{_x:350, _y:35, _width:65, _height:20, label:"Upload"});
		_root["f"+code].createClassObject(ProgressBar,"pb_",333,{_x:10, _y:35, _width:330});
		_root["f"+code].pb_.mode = "manual";
		_root["f"+code].pb_.label = "%1 out of %2 Uploaded";
		_root["f"+code].createClassObject(Label,"label_1",303,{_x:365, _y:65, text:"نوع قالب"});
		_root["f"+code].createClassObject(ComboBox,"com_1",304,{_x:270, _y:65, _width:70});


		_root["f"+code].com_1.addItem({label:"معمولي", fs:"mamoli"});
		_root["f"+code].com_1.addItem({label:"چندتکه", fs:"chandTekE"});



		_root["f"+code].createClassObject(Label,"label_2",305,{_x:215, _y:65, text:"سايز چاپ"});
		_root["f"+code].createClassObject(ComboBox,"com_2",306,{_x:150, _y:65, _width:65});
		_root["f"+code].com_2.addItem({label:"13*18"});
		_root["f"+code].createClassObject(Label,"label_3",307,{_x:110, _y:65, text:"تعداد"});
		_root["f"+code].createClassObject(NumericStepper,"num_1",308,{_x:40, _y:65, _width:65});
		_root["f"+code].num_1.maximum = 100;
		_root["f"+code].createClassObject(Label,"label_4",309,{_x:365, _y:95, text:"برش"});
		_root["f"+code].createClassObject(ComboBox,"com_4",310,{_x:210, _y:95, _width:130});
		_root["f"+code].createClassObject(Label,"label_5",311,{_x:170, _y:95, text:"رنگ"});
		_root["f"+code].com_4.addItem({label:"13*18"});
		_root["f"+code].createClassObject(ComboBox,"com_5",312,{_x:100, _y:95, _width:65});
		_root["f"+code].com_5.addItem({label:"سفيد", data:"sefid"});
		_root["f"+code].com_5.addItem({label:"سياه", data:"siah"});
		_root["f"+code].createClassObject(TextArea,"deatile_1",313,{_x:10, _y:125, _width:265, _height:110, html:true});
		_root["f"+code].createClassObject(Loader,"loader_1",314,{_x:280, _y:125, _width:130, _height:105, scaleContent:true, contentPath:"uploadPRV.jpg"});




		_root["f"+code]["browse_btn_"+code].enabled = false;
		_root["f"+code]["upload_btn_"+code].enabled = false;
		_root["setAS_"+code] = new upload();
		_root["setAS_"+code].setAction(code);


	}
	trace(Number(NM_.value));
	main_form.setSize(430,265+Number(NM_.value)*20);
	sep_1._y = main_form._y+main_form.height+15;
	catch_1._y = main_form._y+main_form.height+35;

};




var rbListener:Object = new Object();
rbListener.click = function(evt_obj:Object) {
	if (evt_obj.target.selection.data == 1) {
		_root.catch_1.tx_1.enabled = false;
		_root.catch_1.tx_2.enabled = true;
	} else {
		_root.catch_1.tx_2.enabled = false;
		_root.catch_1.tx_1.enabled = true;
	}
};
// Add listener.
catch_1.radioGroup.addEventListener("click",rbListener);



var lvSend:LoadVars = new LoadVars();
var lvReceive:LoadVars = new LoadVars();

_root.catch_1.submite_btn.onRelease = function() {



	lvSend.address = _root.address.text;
	lvSend.tell = _root.tell.text;
	lvSend.name = _root.name.text;
	lvSend.mail = _root.mail.text;

	lvSend.type = "";
	lvSend.size = "";
	lvSend.cut = "";
	lvSend.color = "";
	lvSend.num = ""
	for (i=0; i<(NM_.value); i++) {

		code = i+1;
		lvSend.type += "/"+_root["f"+code].com_1.selectedItem.fs;
		lvSend.size += "/"+_root["f"+code].com_2.value;
		lvSend.num =  "/"+_root["f"+code].num_1.value;
		lvSend.cut += "/"+_root["f"+code].com_4.value;
		lvSend.color += "/"+_root["f"+code].com_5.selectedItem.data;


	}

	lvSend.date = _root.catch_1._3.value+"/"+_root.catch_1._2.value+"/"+_root.catch_1._1.value;



	if (catch_1.radioGroup.selection.data == 1) {
		lvSend.cost = "fishNUM::"+_root.catch_1.tx_2.text;
	} else {
		lvSend.cost = "erJaNUM::"+_root.catch_1.tx_1.text;
	}

	lvSend.links = ssl.text;
	lvSend.sendAndLoad("send.php",lvReceive,"POST");
};


lvReceive.onLoad = function(success:Boolean) {
	if (success) {
		_root.catch_1.tx_1.text = this.result;
		if (this.result == "success") {
			getURL("success.php");
		} else {
			///WINK:D
		}
	}
};



function validateForm():Boolean {
	if (mcName.tInput.text == "" || mcSurname.tInput.text == "" || mcAge.tInput.text == "" || mcEmail.tInput.text == "") {
		return false;
	}
	return true;
}


function clearTextFields():Void {
	mcName.tInput.text = "";
	mcSurname.tInput.text = "";
	mcAge.tInput.text = "";
	mcEmail.tInput.text = "";
}


function alert(message:String):Void {
	getURL("javascript:alert('"+message+"');");
}


و فایل PHP که عملیات کپی محتوا از کلاینت به سرور remote رو انجام میده ...

PHP:
<?php
//create the directory if doesn't exists (should have write permissons)
if(!is_dir("./files")) mkdir("./files", 0755); 
//move the uploaded file
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_FILES['Filedata']['name']);
chmod("./files/".$_FILES['Filedata']['name'], 0777);
?>



موفق و پیروز باشی ..
 
بالا