Home / Articles / Adobe Flash / How to Upload a File by Using the Flash FileReference Object

How to Upload a File by Using the Flash FileReference Object

Contents

  1. How to Code the ActionScript
  2. How to Write the PHP
  3. Conclusion

Article Description

Flash has long lacked the ability to upload files, a standard function in programming languages. Kris Hadlock cheers the addition of the FileReference object in Flash 8; by combining a bit of ActionScript and PHP, it's now quite simple to create a Flash file-uploading GUI.

Like this article? We recommend

Macromedia Flash 8: Training from the Source

Macromedia Flash 8: Training from the Source

$44.99

How to Write the PHP

The PHP for handling the file upload is a very small and simple script. (Note that no security is added to the script; I’m leaving that part to you.) The method that we use to move the file to a specific location on the server is move_uploaded_file. This method takes two parameters: a string filename representing the selected file, and a string destination representing the server location where we want the file to be uploaded.

move_uploaded_file($_FILES[’Filedata’][’tmp_name’], "./files/".$_FILES[’Filedata’][’name’]);

The second line of code handles setting the correct permissions for UNIX and Linux servers. In this example, we set full permission for the uploaded file.

chmod("./files/".$_FILES[’Filedata’][’name’], 0777);
3. Conclusion | Next Section Previous Section