Hi,
I need help with uploading a image from Flash.
And before you say anything about this is a asp.net forum, I have to say that flash can't upload files to a server by itself, but needs another scripting language for this. We have been using a PHP-script for devoloping, and it looks like this:
<?php
//create the directory if doesn't exists (should have write permissons)
if(!is_dir("./temp_files")) mkdir("./temp_files", 0755);
//move the uploaded file
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./temp_files/".$_FILES['Filedata']['name']);
chmod("./temp_files/".$_FILES['Filedata']['name'], 0777);
?>
The Flash-application calls this script with ActionScript 2.0 like this:
//Allow this domain
System.security.allowDomain("sub.mydomain.com");
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 += "Vald fil: " + selectedFile.name + "\n";
// Upload the file to the PHP script on the server.
selectedFile.upload("http://sub.mydomain.com/temp_upload.php");
};
// the file is starting to upload.
listener.onOpen = function(selectedFile:FileReference):Void {
_root.laddabild.gotoAndPlay(2);
statusArea.text += "Skickar " + selectedFile.name + "\n"; }; //Possible file upload errors listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
imagePane.contentPath = "error";
_root.laddabild.gotoAndStop(1);
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 += "Uppladdning klar.\nSkickar foto " + selectedFile.name + " till ramen\n";
//Show file details
details.text = ""
for(i in selectedFile) details.text +="<b>"+i+": "+selectedFile[i]+"\n"
// Call the custom downloadImage() function.
downloadImage(selectedFile.name);
};
var imageFile:FileReference = new FileReference(); imageFile.addListener(listener);
uploadBtn.onPress = uploadImage;
imagePane.addEventListener("complete", 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";
}
} Now I don't know anything about Flash, or ActionScript, but I know ASP.NET. However, I cant find the .NET equivalent of that PHP-script. I've done quite a bit of searching, and come up empty handed. But someone has to have done this before..? I can't use PHP because of the web servers limitations.
Any help is appreciated!