# File Upload Using Flash 8

**URL:** <https://forum.kirupa.com/t/file-upload-using-flash-8/168188>\
**Category:** Uncategorized\
**Created:** [November 4, 2005, 5:10pm UTC](https://forum.kirupa.com/t/file-upload-using-flash-8/168188 "2005-11-04T17:10:14Z")\
**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:** [November 4, 2005, 5:10pm UTC](https://forum.kirupa.com/t/file-upload-using-flash-8/168188/1 "2005-11-04T17:10:14Z")

</div>

No one seems to respond in the Flash 8 forum… So here I am, please help thank you…

Does any body know how to get this dam code to upload video files as well. Every tut I come accross with Flash 8 upload is dealing with uploading images only …HELP HELP HELP

Here is the PHPH Code.

\<?php

$MAXIMUM\_FILESIZE = 1024 \* 200; // 200KB  
$MAXIMUM\_FILE\_COUNT = 10; // keep maximum 10 files on server  
echo exif\_imagetype($\_FILES[‘Filedata’]);  
if ($\_FILES[‘Filedata’][‘size’] \<= $MAXIMUM\_FILESIZE) {  
move\_uploaded\_file($\_FILES[‘Filedata’][‘tmp\_name’], “./temporary/”.$\_FILES[‘Filedata’][‘name’]);  
$type = exif\_imagetype("./temporary/".$\_FILES[‘Filedata’][‘name’]);  
if ($type == 1 || $type == 2 || $type == 3) {  
rename("./temporary/".$\_FILES[‘Filedata’][‘name’], “./images/”.$\_FILES[‘Filedata’][‘name’]);  
} else {  
unlink("./temporary/".$\_FILES[‘Filedata’][‘name’]);  
}  
}  
$directory = opendir(’./images/’);  
$files = array();  
while ($file = readdir($directory)) {  
array\_push($files, array(’./images/’.$file, filectime(’./images/’.$file)));  
}  
usort($files, sorter);  
if (count($files) \> $MAXIMUM\_FILE\_COUNT) {  
$files\_to\_delete = array\_splice($files, 0, count($files) - $MAXIMUM\_FILE\_COUNT);  
for ($i = 0; $i \< count($files\_to\_delete); $i++) {  
unlink($files\_to\_delete[$i][0]);  
}  
}  
print\_r($files);  
closedir($directory);

function sorter($a, $b) {  
if ($a[1] == $b[1]) {  
return 0;  
} else {  
return ($a[1] \< $b[1]) ? -1 : 1;  
}  
}  
?\>

* * *

// Flash code from sample app in Flash 8…  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
//Copyright © 2005 Macromedia, Inc. All Rights Reserved.  
//The following is Sample Code and is subject to all restrictions on  
//such code as contained in the End User License Agreement accompanying  
//this product.  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

System.security.allowDomain(“[http://www.helpexamples.com](http://www.helpexamples.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 {

// Update the TextArea to notify the user that 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”);  
};

// When the file begins to upload the onOpen() method is called, so  
// notify the user that the file is starting to upload.  
listener.onOpen = function(selectedFile:FileReference):Void {  
statusArea.text += "Opening " + selectedFile.name + "  
";  
};

// Once the file has uploaded, the onComplete() method is called.  
listener.onComplete = function(selectedFile:FileReference):Void {

// Notify the user that Flash is starting to download the image.  
statusArea.text += "Downloading " + selectedFile.name + " to player  
";

// Add the image to the ComboBox component.  
imagesCb.addItem(selectedFile.name);

// Set the selected index of the ComboBox to that of the most recently-  
// added image.  
imagesCb.selectedIndex = imagesCb.length - 1;

// Call the custom downloadImage() function.  
downloadImage();  
};

var imageFile:FileReference = new FileReference();  
imageFile.addListener(listener);

uploadBtn.addEventListener(“click”, uploadImage);  
imagesCb.addEventListener(“change”, downloadImage);  
imagePane.addEventListener(“complete”, imageDownloaded);

// If the image does not download, the event object’s total property  
// will equal -1. In that case, display a message to the user.  
function imageDownloaded(event:Object):Void {  
if(event.total == -1) {  
imagePane.contentPath = “Message”;  
}  
}

// When the user selects an image from the ComboBox, or when the downloadImage()  
// function is called directly from the listener.onComplete() method,  
// the downloadImage() functino sets the contentPath of the ScrollPane in order  
// to start downloading the image to the player.  
function downloadImage(event:Object):Void {  
imagePane.contentPath = “images/” + imagesCb.value;  
}

// When the user clicks the button Flash calls the uploadImage() function,  
// and it opens a file browser dialog.  
function uploadImage(event:Object):Void {  
imageFile.browse([{description: “Media Files”, extension: “_.mov;_.swf;_.jpg;_.gif;\*.png”}]);  
}
