You can get the files at the link provided:
http://www.developphp.com/Flash_tutorials/show_tutorial.php?tid=6&t=Browse_and_Upload_Files_Using_Flash_and_AS3
This is the AS3 code:
uploadMsg.visible = false;
var URLrequest:URLRequest = new URLRequest("http://www.[yoursite.com].com/uploader_script.php");
var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
var textTypes:FileFilter = new FileFilter("Text Files (*.txt, *.rtf)", "*.txt; *.rtf");
var allTypes:Array = new Array(imageTypes, textTypes);
var fileRef:FileReference = new FileReference();
fileRef.addEventListener(Event.SELECT, syncVariables);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
browse_btn.addEventListener(MouseEvent.CLICK, browseBox);
upload_btn.addEventListener(MouseEvent.CLICK, uploadVars);
function browseBox(event:MouseEvent):void {
fileRef.browse(allTypes);
}
function uploadVars(event:MouseEvent):void {
uploadMsg.visible = true;
fileRef.upload(URLrequest);
upload_btn.visible = false;
}
function syncVariables(event:Event):void {
fileDisplay_txt.text = "" + fileRef.name;
blocker.visible = false;
upload_btn.visible = true;
progressBar.width = 2;
var variables:URLVariables = new URLVariables();
variables.todayDate = new Date();
variables.Name = "Dude"; // This could be an input field variable like in my contact form tutorial : )
variables.Email = "someDude@someEmail.com"; // This one the same
URLrequest.method = URLRequestMethod.POST;
URLrequest.data = variables;
}
function completeHandler(event:Event):void {
uploadMsg.visible = false;
blocker.visible = true;
status_txt.text = fileRef.name + " has been uploaded.";
fileDisplay_txt.text = "";
}
function progressHandler(event:ProgressEvent):void {
progressBar.width = Math.ceil(200*(event.bytesLoaded/event.bytesTotal));
}
The php code:
<?php
$todayDate = $_POST['todayDate'];
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$filename = $_FILES['Filedata']['name'];
$filetmpname = $_FILES['Filedata']['tmp_name'];
$fileType = $_FILES["Filedata"]["type"];
$fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000);
move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$filename);
$myFile = "logFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "\n\ntodayDate: $todayDate \n Name: $Name \n Email: $Email \n ssid: $ssid \n FileName: $filename \n TmpName: $filetmpname \n Type: $fileType \n Size: $fileSizeMB MegaBytes";
fwrite($fh, $stringData);
fclose($fh);
?>
All Script Written By: Adam Khoury @ www.developphp.com
So as far as most people are concerned this code works. But I can't get it working on my site unless I take out the the vars in AS3 and just upload(), or if i change the upload to a vars load(). But I need both for the code to do what I need. Any thoughts?
PS. This is not the code I am using for my site but it is almost the same.