Trouble File Uploading (FileReference)

Heya guys,

I’m looking to explore file uploading within Flash.

At the moment I’ve been using Kirupa and the Flash help tutorials on using FileReference.

I have managed to successfully get this to work on my localserver, however, when I upload online (and reset the paths successfully) the file uploads yet I receive an onHTTPError and the file isn’t uploaded. I’ve tried tracing the error to find out the result but I’ve had no luck.

Here’s the current code I’m working with:


import flash.net.FileReference;

var allTypes:Array = new Array();
var imageTypes:Object = new Object();
imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png";
allTypes.push(imageTypes);

var textTypes:Object = new Object();
textTypes.description = "Text Files (*.txt, *.rtf)";
textTypes.extension = "*.txt;*.rtf";
allTypes.push(textTypes);

var listener:Object = new Object(); 

listener.onSelect = function(file:FileReference):Void {
    trace("onSelect: " + file.name);
    if(!file.upload("http://www.slightintention.co.uk/imagetest/imageUpload.php")) {
        trace("Upload dialog failed to open.");
    }
}

listener.onCancel = function(file:FileReference):Void {
    trace("onCancel");
}

listener.onOpen = function(file:FileReference):Void {
    trace("onOpen: " + file.name);
}

listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
    trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
}

listener.onComplete = function(file:FileReference):Void {
    trace("onComplete: " + file.name);
}

listener.onHTTPError = function(file:FileReference):Void {
    trace("onHTTPError: " + file.name);
}

listener.onIOError = function(file:FileReference, httpError:Number):Void {
    trace("onIOError: " + file.name);
}

listener.onSecurityError = function(file:FileReference, errorString:String):Void {
    trace("onSecurityError: " + file.name + " errorString: " + errorString);
}

var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);
fileRef.browse(allTypes);



<?php

$path = "/home/sdiamond/public_html/imagetest/";

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

echo $path;
echo "Your image is called: $_FILES{'Filedata']['name']";

$filename = "/home/sdiamond/public_html/imagetest/logFile.txt";
$content = $_FILES['Filedata']['name'];

if(!is_writable($filename))
{
	die('Not chmoded');
}
echo '<br /><br />';
$handle = fopen($filename,'a');

$write = fwrite($handle, $content);

if($write == true)
{
	echo 'Good';
}
else
{
	echo 'Bad';
}

move_uploaded_file($_FILES['Filedata']['tmp_name'],$path) or die("failed");

echo "&response=File has been uploaded to ".$path;


?>

I also have a html input box to upload files and that successfully works and the problem seems to be with Flash, yet I can’t seem to figure out why (this is my first time using FileReference). Also, all my files/folders are chmoded to 0777.

Any info or advice greatly appreciated.