# Flash 8 File Upload Help.. Source posted

**URL:** <https://forum.kirupa.com/t/flash-8-file-upload-help-source-posted/166752>\
**Category:** flash\
**Created:** [October 22, 2005, 3:37pm UTC](https://forum.kirupa.com/t/flash-8-file-upload-help-source-posted/166752 "2005-10-22T15:37:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hogfish](https://avatars.discourse-cdn.com/v4/letter/h/b19c9b/32.png) [@hogfish](https://forum.kirupa.com/u/hogfish)\
**Post date:** [October 22, 2005, 3:37pm UTC](https://forum.kirupa.com/t/flash-8-file-upload-help-source-posted/166752/1 "2005-10-22T15:37:56Z")

</div>

[left][left]I got this source below from ([http://www.flash-db.com/Tutorials/upload/](http://www.flash-db.com/Tutorials/upload/)), what I need is to add a file size checker on it. I want to be able to control the size of files users can upload.  
Thanks for your help, my first time using Flash 8.

* * *

//Allow this domain  
System.security.allowDomain(“[http://localhost/](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 + "  
";  
// 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 += "Uploading " + selectedFile.name + "  
";  
};  
//Possible file upload errors  
listener.onHTTPError = function(file:FileReference, httpError:Number):Void {  
imagePane.contentPath = “error”;  
imagePane.content.errorMSG.text = "HTTPError number: “+httpError +”  
File: "+ 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+”  
File: "+ 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 += “Upload finished.  
Now downloading " + selectedFile.name + " to player  
“;  
//Show file details  
details.text = “”  
for(i in selectedFile) details.text +=”\<b\>”+i+":\</b\> “+selectedFile\*+”  
"  
// 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: “Media Files”, extension: “_.jpg;_.gif;_.png;_.mov;_.rm;_.wmv;\*.swf”}]);

}

// 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/” + file;  
}

stop()

* * *

[/left][/left]
