Thanks for taking a look at this code.
As I mentioned it earlier I have mix results with it:
It works here:
-My localhost testing from within flash, and from safari, and firefox.
-Server A (a friend's): from any windows PC and Mac browser
-Server B (where it should be finally hosted): Only works from windows PC
browsers. Whenever I tried from a mac browser I get this error:
Error #2038: File I/O Error. URL: url of php script.
Earlier I made the php script that I'm addressing print a confirmation
variable whenever it is called. In the situations the upload fails it seems
that flash cannot even address it (!) since the script doesn't even print that
variable.
So here's the code:
// FLASH MOVIE: IT IS A SINGLE BUTTON MOVIE TO PROMPT THE UPLOAD,
// AND A TEXT FIELD SHOWING ANY ERROR OR COMPLETED MESSAGES.
//
import flash.events.*;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
Security.loadPolicyFile("
http://www.mauricioarango.net/LAB/SaoPaulo/policy.xml")
;
var totalTransfers:int = 0;
var fr:FileReference;
single.buttonMode = true;
single.addEventListener (MouseEvent.CLICK, uploadFiles);
function uploadFiles (e:MouseEvent):void {
fr = new FileReference;
fr.browse ();
fr.addEventListener (Event.SELECT, selectHandler);
fr.addEventListener (Event.OPEN, openHandler);
fr.addEventListener (ProgressEvent.PROGRESS, progressHandler);
fr.addEventListener (Event.COMPLETE, completeHandler);
fr.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);
}
function selectHandler (e:Event):void {
var request:URLRequest = new URLRequest();
//request.url = "
http://www.mauricioarango.net/LAB/SaoPaulo/test.php"; request.url = "http://localhost/~mauro/SaoPaulo/test.php";
request.method = URLRequestMethod.POST;
//
fr.upload (request);
}
function openHandler (e:Event):void {
//
}
function progressHandler (e:Event):void {
//
}
function completeHandler (e:Event):void {
//
totalTransfers ++;
errorsReturn.appendText('\n FILE TRANSFERED'+ ' ' +totalTransfers );
}
function ioErrorHandler (event:IOErrorEvent):void {
//trace ("ioErrorHandler: " + event);
trace (event.currentTarget);
trace (event.target);
trace (event.text);
errorsReturn.text = event.text;
}
///////////////////////////////////////
///////////////////////////////////////
// PHP FILE: ALL IT DOES IS TO PUT THE UPLOADED FILE IN THE DESTINATION
DIRECTORY
<?PHP
$target_path = "uploads/";
// Add the original filename to our target path.
// Result is "uploads/filename.extension"
$target_path = $target_path . basename( $_FILES['Filedata']['name']);
$_FILES['Filedata']['tmp_name'];
move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path);
echo '1';
?>