FileReference:Class
Tuesday, May 15th, 2007The Flash FileReference Class is a tool for uploading files by:
- Popping up a browse box, prompting the user to define the file they would like to upload
- Uploading the required file, using either php, coldfusion, or asp.
- Keeping Flash up to date on the progress of uploading the file.
- And returning to Flash either an error or else it notifies Flash that it uploading has been completed successfully.
The properties of the FileReference :Class are as follows:
- addListener(listener:Object) :Function
- browse(typelist:Array) :Function
- cancel:Function
- creationDate:Date[read-only]
- creator:String[read-only]
- download
- modificationDate:Date[read-only]
- name:String[read-only]
- onCancel:Function -runs when user cancels
- onComplete:Function -runs when uploading completes
- onHTTPError:Function -runs when a HTTPError is encountered
- onIOError:Function -runs when an IOError is encountered
- onOpen:Function -runs when file is Opened
- onProgress:Function -runs when upload progress is made
- onSecurityError:Function -runs when a security error is encountered
- onSelect:Function -runs when user selects which file to upload
- removeListener:Function
- size:Number[read-only]
- type:String[read-only]
- upload:Function
Judging by the number of people having problems with the FileReference class, a list of causes of errors would be helpful. If an error you are currently having is not listed, then please feel free to comment on it.
- 406 error
- This might be able to be fixed by going to the root directory on your site, and adding the following lines to .htaccess (if it is not there, then create it)
- SecFilterEngine Off
- SecFilterScanPOST Off
- or, on the other hand, if your page is under a secure connection,
Flash cannot upload under a secure connection, so if you are trying for example to upload to https://mysite.com/upload.php, it won’t work, because flash cannot upload under a secure connection, however, you can upload to http://mysite.com/upload.php - or a combination of both
- This might be able to be fixed by going to the root directory on your site, and adding the following lines to .htaccess (if it is not there, then create it)
- If you would like to have an error listed, please comment on your error, and an administrator may add it to the blog
Also included in this blog is a list of other articles on the FileReference Class and it’s errors
The code for php is:
$fileName = basename($_FILES[”Filedata”][”name”]);
$uploadFile = “images/uploaded/” . $_GET[”date”] . “-” . $fileName;if (move_uploaded_file($_FILES[”Filedata”][”tmp_name”], $uploadFile)) {
chmod(dirname(__FILE__) . “/” . $uploadFile, 0777);
print 1;
}else{
print 0;
}
?>
The code for coldfusion:
The code for asp:
<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”1252″%>
<%Set theForm = Server.CreateObject(”ABCUpload4.XForm”)
theForm.Overwrite = True ‘ overwrite existing files
.
For Each theFile in theForm.Files
If theFile.FileExists Then
‘ save in virtual directory
theFile.Save “temp\” & theFile.FileName
Response.Write(”1 ” & theFile.FileName)
Else
Response.Write(”0″)
End If
NextSet theForm = nothing
%>
If you have any comments or questions please feel free to let us know… and
Thanks for reading
…Also, a tutorial on this is coming soon!