Flash, Actionscript and PHP for file uploading - HELP needed!

I have some Actionscript code that will hopefully upload multiple files to my web server (via a PHP script). A user simply selects their files by clicking on a “select” button, then uploads them by clicking “upload”. That all makes sense. To see a current version of this, goto www.pixmaker.com/fileUploader, sign-in using (username: test1, password: freedom7901), and click the active link.

However, I also want the user to fill out some text that will describe each file upload (the property name) - so I’ve also included an input text box in the flash panel, and called this instance “property_txt”. Can someone give me the correct code so that this value can be sent to the php script along with the file information? I’d like to access the value via the GET or POST function in the PHP code.


Here’s my AS code:

import flash.net.;
var currentListItem:Number;
var fullFileBytes:Number;
var progressBar:MovieClip;
var reference:FileReference;
var totalSize:Number;
var referenceList:FileReferenceList = new FileReferenceList();
var listStatus:Array = new Array();
var referenceListener:Object = new Object();
var errorFlag:Boolean = false;
var scriptLocation:String = ‘uploader.php’;
var progressBarHeight:Number = 10;
var progressBarY:Number = 80;
var progressBarColor:Number = 0x66ccff;
referenceList.addListener(referenceListener);
uploadButton_mc._visible = false;
chooseButton_mc.onRelease = choose;
uploadButton_mc.onRelease = uploadCurrent;
referenceListener.onSelect = activateUploadButton;
referenceListener.onProgress = updateProgress;
referenceListener.onComplete = tryNextUpload;
referenceListener.onHTTPError = handleError;
referenceListener.onIOError = handleError;
referenceListener.onSecurityError = handleError;
function activateUploadButton():Void {
currentListItem = 0;
totalSize = 0;
fullFileBytes = 0;
progressBar = makeProgressBar(310, progressBarY);
reference = referenceList.fileList[currentListItem];
reference.addListener(referenceListener);
uploadButton_mc._visible = true;
display_txt.text = ‘’;
for (var i:Number = 0; i<referenceList.fileList.length; i++) {
display_txt.text += referenceList.fileList
.name+’
‘;
listStatus* = ‘0%’;
totalSize += referenceList.fileList*.size;
}
delete i;
}
function choose():Void {
referenceList.browse([{description:‘All Files (.)’, extension:’.’}]);
}
function handleError(errorName:String, detail:Object):Void {
errorFlag = true;
if (arguments.length === 2) {
if (typeof detail === ‘number’) {
listStatus[currentListItem] = ‘HTTP Error #’+detail;
} else {
listStatus[currentListItem] = 'Security Error: ‘+detail;
}
} else {
listStatus[currentListItem] = ‘IO Error’;
}
updateStatusText();
tryNextUpload();
}
function makeProgressBar(x:Number, y:Number):MovieClip {
var bar:MovieClip = createEmptyMovieClip(‘progressBar_mc’, 0);
bar._visible = false;
bar.beginFill(progressBarColor);
bar.lineTo(Stage.width, 0);
bar.lineTo(Stage.width, progressBarHeight);
bar.lineTo(0, progressBarHeight);
bar.lineTo(0, 0);
bar.endFill();
bar._width = 0;
bar._visible = true;
bar._x = x;
bar._y = y;
return bar;
}
function restart():Void {
removeMovieClip(progressBar);
if (errorFlag) {
errorFlag = false;
} else {
display_txt.text = ‘Success! Your files have been uploaded.’;
}
uploadButton_mc._visible = false;
chooseButton_mc._visible = true;
}
function tryNextUpload():Void {
reference.removeListener(referenceListener);
fullFileBytes += reference.size;
if (currentListItem === referenceList.fileList.length-1) {
restart();
} else {
reference = referenceList.fileList[++currentListItem];
reference.addListener(referenceListener);
uploadCurrent();
}
}
function updateProgress(fileReference:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
listStatus[currentListItem] = Math.ceil((bytesLoaded/bytesTotal)100)+’%’;
updateStatusText();
progressBar._width = Math.ceil(220
((fullFileBytes+bytesLoaded)/totalSize));
}
function updateStatusText():Void {
display_txt.text = ‘’;
for (var i:Number = 0; i<referenceList.fileList.length; i++) {
display_txt.text += referenceList.fileList*.name+’ - ‘+listStatus*+’
';
}
}
function uploadCurrent():Void {
chooseButton_mc._visible = false;
reference.upload(“uploader.php?property=”+property_txt);
}


In addition, can someone take a look at my PHP script and tell me what additions I should make? I want the files to be saved in a newly created directory each time, depending on the user’s login details, and the “property” value they entered. For this example, it would be:
CURRENT DIRECTORY LOCATION -> COMPANY NAME (= username) -> BRANCH NAME (= password) -> PROPERTY
I’ve assigned $uploadDir to this. Does it look correct inthe code below?
So is my $uploaddir correct?

Here’s the code:


<?php

$company = $_SESSION[‘Company’];
$branch = $_SESSION[‘Branch’];
$property = $_GET[‘property’];

//what is the directory path I want to upload to?
$uploadDir = ‘/$company/$branch/$property/’;
//create the directory (should have write permissons)
$old_umask = umask(0);
mkdir($uploadDir, 0777);
umask($oldumask);

//move the uploaded file
$uploadFile = $uploadDir . $_FILES[‘Filedata’][‘name’];
$result = move_uploaded_file($_FILES[‘Filedata’][‘tmp_name’], $uploadFile);
chmod($uploadDir . $_FILES[‘Filedata’][‘name’], 0777);

if ($result)
{
$message = “<result><status>OK</status><message>$file_name uploaded successfully.</message></result>”;
}
else
{
$message = “<result><status>Error</status><message>Something is wrong with uploading a file.</message></result>”;
}

echo $message;

?>


Any help with any of this would be greatly appreciated. Thanks! (I have viewed many tutorials on this already, and I’m still having problems.)

if i want to read the bible, i will go to church, but now i dont have time for this so please make your text more focused…

helloo

same problem over here…
i can’t seem to upload multiple file with file referenceList.
here is my AS 2.0 script

import flash.net.FileReference;
import flash.net.FileReferenceList;
import mx.controls.gridclasses.DataGridColumn;

imagePane.setSize(400, 350);
imagePane.move(75, 25);
browseBtn.label = "Browse";
uploadBtn.label = "Upload";
imageLbl.move(75, 430);
imageLbl.text = "Select Image";
statusLbl.move(210, 390);
statusLbl.text = "Status";
imagesCb.move(75, 450);
statusArea.setSize(250, 100);
statusArea.move(210, 410);

var filePathArray:Array = new Array();

/* 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:FileReferenceList, bytesLoaded:Number, bytesTotal:Number):Void {
    /* Update the TextArea to notify the user that Flash is attempting to upload the image. */
    //statusArea.text += "Attempting to upload " + selectedFile.name + "
";
	/* updating the datagrid component and adding the files */
	var list:Array = selectedFile.fileList;
    var item:FileReference;
    for(var i:Number = 0; i < list.length; i++) {
        item = list*;
		filePathArray* = list*;
		myDP_array.push({name:item.name});
		my_dg.dataProvider = myDP_array;
        trace("name: " + list*.name + " size: " + item.size/1024);
    }

	
};

/* 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 + "
";
};

listener.onHTTPError = function(errorName:String, detail:Object){
	status.text = " HTTP Error #"+detail;
};

listener.onIOError = function(errorName:String, detail:Object){
	status.text = "IO Error";	
};


listener.onProgress = function(selectedFile:FileReferenceList, bytesLoaded:Number, bytesTotal:Number):Void {
	//display the loader progress bar
	my_pb.setProgress(bytesLoaded, bytesTotal);
    trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
	
};

/* When 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();
};
//creating an array to put it into the datagrid
var myDP_array:Array = new Array();

var column = new DataGridColumn("name");
column.headerText = "File name";
column.width = 150;
my_dg.addColumn(column);

var column = new DataGridColumn("upload");
column.headerText = "Upload %";
column.width = 150;
my_dg.addColumn(column);


var imageFile:FileReferenceList = new FileReferenceList();
imageFile.addListener(listener);
imagePane.addEventListener("complete", imageDownloaded);
imagesCb.addEventListener("change", downloadImage);
uploadBtn.addEventListener("click", uploadImage);
browseBtn.addEventListener("click", browseImage);

/* 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() function sets the contentPath of the ScrollPane in order to start downloading the image to the player. */
function downloadImage(event:Object):Void {
    imagePane.contentPath = "uploads/" + imagesCb.value;
}

/* When the user clicks the button, Flash calls the browseImage() function, and it opens a file browser dialog box. */
function browseImage(event:Object):Void {
    imageFile.browse();
}

/*when the user click on upload buttons, flash calls all uploadImage() function*/

function uploadImage(event:Object):Void {
	var a =0;
	for(a=0;a<myDP_array.length;a++){
	trace(imageFile.fileList[a].name);
	imageFile.fileList[a].upload("uploader.php?rand="+new Date().getTime());
	}
}


and that’s the php

<?php
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['Filedata']['name']); 

if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['Filedata']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
    echo "Error:" . basename( $_FILES['Filedata']['error']);
}
?>

please HELP!!