saswww
24.03.2013, 23:42
Здравствуйте. Есть загрузка внешнего файла (фото) с локального компьютера во флеш на сервере. Картинка сразу появляется на сервере и загружается в папку там же. Есть второй код - форма отправки письма на почту. Хотелось бы совместить - сделать форму отправки письмана почту с загруженным фото, и еще сделать проверку загружаемого файла по расширению.
Вот код заррузки файла:
//Allow this domain
System.security.allowDomain("http://localhost/");
import flash.net.FileReference;
// The listener object listens for FileReference events.
var listener:Object = new Object();
// When the user selects a file, the onSelect() method is called, and
// passed a reference to the FileReference object.
listener.onSelect = function(selectedFile:FileReference):Void {
//clean statusArea and details area
// statusArea.text = details.text = ""
// Flash is attempting to upload the image.
// statusArea.text += "Attempting to upload " + selectedFile.name + "\n";
// Upload the file to the PHP script on the server.
selectedFile.upload("upload.php");
};
// the file is starting to upload.
listener.onOpen = function(selectedFile:FileReference):Void {
statusArea.text += "Файл " + selectedFile.name + "\n";
};
//Possible file upload errors
listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "HTTPError number: "+httpError +"\nFile: "+ file.name;
}
listener.onIOError = function(file:FileReference):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "IOError: "+ file.name;
}
listener.onSecurityError = function(file:FileReference, errorString:String):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "SecurityError: "+SecurityError+"\nFile: "+ file.name;
}
// the file has uploaded
listener.onComplete = function(selectedFile:FileReference):Void {
// Notify the user that Flash is starting to download the image.
statusArea.text += "Загрузка завершена.\n";
//Show file details
// details.text = ""
// for(i in selectedFile) details.text +="<b>"+i+":</b> "+selectedFile[i]+"\n"
// Call the custom downloadImage() function.
downloadImage(selectedFile.name);
};
var imageFile:FileReference = new FileReference();
imageFile.addListener(listener);
uploadBtn.onPress = uploadImage;
imagePane.addEventListener("Завершена", imageDownloaded);
// Call the uploadImage() function, opens a file browser dialog.
function uploadImage(event:Object):Void {
imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png"}]);
}
// If the image does not download, the event object's total property
// will equal -1. In that case, display am error message
function imageDownloaded(event:Object):Void {
if(event.total == -1) {
imagePane.contentPath = "error";
}
}
// show uploaded image in scrollPane
function downloadImage(file:Object):Void {
imagePane.contentPath = "./files/files/" + file;
}
stop()
Второй код отправки письма:
tf_fmt = new TextFormat();
tf_fmt.color = "0xEEEEEE";
_root.createTextField("name_txt", 1, 10, 10, 300, 20);
with (name_txt) {
border = true;
borderColor = "0xffffff";
name_txt.textColor = "0xffffff";
type = "input";
multiline = false;
text = "Ваше ИМЯ";
setTextFormat(tf_fmt);
}
name_txt.onSetFocus = function() {
this.text = "";
delete this.onSetFocus;
};
_root.createTextField("mail_txt", 2, 10, 40, 300, 20);
with (mail_txt) {
border = true;
borderColor = "0xffffff";
mail_txt.textColor = "0xffffff";
type = "input";
multiline = false;
text = "Ваш e-mail";
setTextFormat(tf_fmt);
}
mail_txt.onSetFocus = function() {
this.text = "";
delete this.onSetFocus;
};
_root.createTextField("message_txt", 3, 10, 70, 300, 200);
with (message_txt) {
border = true;
borderColor = "0xffffff";
message_txt.textColor = "0xffffff";
type = "input";
multiline = true;
text = "Ваше сообщение";
setTextFormat(tf_fmt);
}
message_txt.onSetFocus = function() {
this.text = "";
delete this.onSetFocus;
};
_root.attachMovie("button", "but_mc", 4, {_x:10, _y:280});
but_mc.createTextField("tf", 1, 0, 0, 300, 20);
b_fmt = new TextFormat();
b_fmt.color = "0xFFFFFF";
b_fmt.align = "center";
with (but_mc.tf) {
selectable = false;
text = "Send";
setTextFormat(b_fmt);
}
but_mc.onPress = function() {
F_sendMail(name_txt.text, mail_txt.text, message_txt.text);
};
F_sendMail = function (Name, Mail, Message) {
_root.createEmptyMovieClip("v", 120);
v.name = Name;
v.mail = Mail;
v.message = Message;
v.loadVariables("http://www.mydomain.com/email.php", "POST");
message_txt.text = "Сообщение ОТПРАВЛЕНО";
mail_txt.text = "";
name_txt.text = "";
};
System.useCodepage = true;
Вот код заррузки файла:
//Allow this domain
System.security.allowDomain("http://localhost/");
import flash.net.FileReference;
// The listener object listens for FileReference events.
var listener:Object = new Object();
// When the user selects a file, the onSelect() method is called, and
// passed a reference to the FileReference object.
listener.onSelect = function(selectedFile:FileReference):Void {
//clean statusArea and details area
// statusArea.text = details.text = ""
// Flash is attempting to upload the image.
// statusArea.text += "Attempting to upload " + selectedFile.name + "\n";
// Upload the file to the PHP script on the server.
selectedFile.upload("upload.php");
};
// the file is starting to upload.
listener.onOpen = function(selectedFile:FileReference):Void {
statusArea.text += "Файл " + selectedFile.name + "\n";
};
//Possible file upload errors
listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "HTTPError number: "+httpError +"\nFile: "+ file.name;
}
listener.onIOError = function(file:FileReference):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "IOError: "+ file.name;
}
listener.onSecurityError = function(file:FileReference, errorString:String):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "SecurityError: "+SecurityError+"\nFile: "+ file.name;
}
// the file has uploaded
listener.onComplete = function(selectedFile:FileReference):Void {
// Notify the user that Flash is starting to download the image.
statusArea.text += "Загрузка завершена.\n";
//Show file details
// details.text = ""
// for(i in selectedFile) details.text +="<b>"+i+":</b> "+selectedFile[i]+"\n"
// Call the custom downloadImage() function.
downloadImage(selectedFile.name);
};
var imageFile:FileReference = new FileReference();
imageFile.addListener(listener);
uploadBtn.onPress = uploadImage;
imagePane.addEventListener("Завершена", imageDownloaded);
// Call the uploadImage() function, opens a file browser dialog.
function uploadImage(event:Object):Void {
imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png"}]);
}
// If the image does not download, the event object's total property
// will equal -1. In that case, display am error message
function imageDownloaded(event:Object):Void {
if(event.total == -1) {
imagePane.contentPath = "error";
}
}
// show uploaded image in scrollPane
function downloadImage(file:Object):Void {
imagePane.contentPath = "./files/files/" + file;
}
stop()
Второй код отправки письма:
tf_fmt = new TextFormat();
tf_fmt.color = "0xEEEEEE";
_root.createTextField("name_txt", 1, 10, 10, 300, 20);
with (name_txt) {
border = true;
borderColor = "0xffffff";
name_txt.textColor = "0xffffff";
type = "input";
multiline = false;
text = "Ваше ИМЯ";
setTextFormat(tf_fmt);
}
name_txt.onSetFocus = function() {
this.text = "";
delete this.onSetFocus;
};
_root.createTextField("mail_txt", 2, 10, 40, 300, 20);
with (mail_txt) {
border = true;
borderColor = "0xffffff";
mail_txt.textColor = "0xffffff";
type = "input";
multiline = false;
text = "Ваш e-mail";
setTextFormat(tf_fmt);
}
mail_txt.onSetFocus = function() {
this.text = "";
delete this.onSetFocus;
};
_root.createTextField("message_txt", 3, 10, 70, 300, 200);
with (message_txt) {
border = true;
borderColor = "0xffffff";
message_txt.textColor = "0xffffff";
type = "input";
multiline = true;
text = "Ваше сообщение";
setTextFormat(tf_fmt);
}
message_txt.onSetFocus = function() {
this.text = "";
delete this.onSetFocus;
};
_root.attachMovie("button", "but_mc", 4, {_x:10, _y:280});
but_mc.createTextField("tf", 1, 0, 0, 300, 20);
b_fmt = new TextFormat();
b_fmt.color = "0xFFFFFF";
b_fmt.align = "center";
with (but_mc.tf) {
selectable = false;
text = "Send";
setTextFormat(b_fmt);
}
but_mc.onPress = function() {
F_sendMail(name_txt.text, mail_txt.text, message_txt.text);
};
F_sendMail = function (Name, Mail, Message) {
_root.createEmptyMovieClip("v", 120);
v.name = Name;
v.mail = Mail;
v.message = Message;
v.loadVariables("http://www.mydomain.com/email.php", "POST");
message_txt.text = "Сообщение ОТПРАВЛЕНО";
mail_txt.text = "";
name_txt.text = "";
};
System.useCodepage = true;