# Flash Uploader with PHP - Need Help

**URL:** https://forum.kirupa.com/t/flash-uploader-with-php-need-help/259713
**Category:** flash
**Created:** [May 8, 2008, 2:50am UTC](https://forum.kirupa.com/t/flash-uploader-with-php-need-help/259713 "2008-05-08T02:50:19Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mojobullfrog](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@mojobullfrog](https://forum.kirupa.com/u/mojobullfrog)
#### Post date: [May 8, 2008, 2:50am UTC](https://forum.kirupa.com/t/flash-uploader-with-php-need-help/259713/1 "2008-05-08T02:50:19Z")

</div>

[COLOR=red]Hi there.[/COLOR]  
[COLOR=red][/COLOR]  
[COLOR=red]I’m creating a multiple file uploader using a flash interface with a php upload script. I just want to make sure my code’s reading correctly, because I’m a bit of a newbie with all this. Any advice would be welcomed. Thanks. I can include a URL soon if that helps.[/COLOR]

* * *

[COLOR=blue]Flash AS Code…[/COLOR]

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 = 200;  
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(8, 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(Stage.width_((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);  
}

[COLOR=red]The last function is what I need help with. I have an input box that people can type a name of a property into (called this “property” in the Var box in Flash). What code do I need to include to have this variable correctly send with the upload function??? I’m not so good with syntaxt.[/COLOR]  
[COLOR=#ff0000][/COLOR]  
[COLOR=#ff0000][/COLOR]  
[COLOR=#ff0000][/COLOR]

[COLOR=black]\*\*\*\*[/COLOR]  
[COLOR=#0000ff]PHP script[/COLOR]  
[COLOR=#0000ff][/COLOR]  
\<?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;

?\>

[COLOR=red]should $uploadDir be referred to like this:  
$uploadDir = “.”/"$company."/".$branch."/".$property."/"";[/COLOR]  
[COLOR=#ff0000][/COLOR]  
[COLOR=red]also, should I be using ‘chown’ anywhere???[/COLOR]
