I have a project where a user can upload an image and it moved to the server via php. All worked fine when the file was flash 9 but I had to convert it to flash 10 for the extra BitmapData functionality. But now regardless of browser and OS the file gets to 100% upload then throws an ioError. Also on my local host it works just fine but when pushed to a live server is where it breaks. Any help would greatly be appreciated.
My as code
private function uploadImageClickHandler(e:MouseEvent):void {
uploadFileRef = new FileReference();
uploadFileRef.addEventListener(Event.SELECT, uploadImageSelectedHandler, false, 0, true);
uploadFileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadImageCompleteHandler, false, 0, true);
uploadFileRef.addEventListener(ProgressEvent.PROGRESS, uploadImageProgressHandler, false, 0, true);
uploadFileRef.addEventListener(IOErrorEvent.IO_ERROR, uploadImageIOErrorHandler, false, 0, true);
var imagesFilter:FileFilter = new FileFilter("Images", "*.jpg;*.jpeg;*.gif;*.png");
uploadFileRef.browse([imagesFilter]);
}
private function uploadImageSelectedHandler(e:Event):void {
var uploadURL:URLRequest = new URLRequest(appURL + "php/upload.php");
uploadURL.method = URLRequestMethod.POST;
var uploadVars:URLVariables = new URLVariables();
uploadVars.userID = userID;
uploadURL.data = uploadVars;
uploadFileRef.upload(uploadURL);
}
And my php code looks like
if(!is_dir("../userImages/".$userID)) {
mkdir("../userImages/".$userID, 0777);
}
include("thumbnail.php");
$now = date("mdYGis");
$filename = strtolower($_FILES['Filedata']['name']);
$filename = str_replace(" ", "_", $filename);
$filename = replace($filename);
/*if (file_exists("../".$nickName."/".$filename)){
@rename("../".$nickName."/".$filename, "../".$nickName."/".$filename."_".$now);
}*/
if(move_uploaded_file($_FILES['Filedata']['tmp_name'], "../userImages/$userID/".$filename)){
chmod("../userImages/$userID/".$filename, 0755);
thumbnail("../userImages/$userID/".$filename, $filename);
}else{
echo "failed to move file";
}
function replace($toEdit){
$badChars = array("!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "|", "?", "/", "<", ">", ",", "`", "~", ":", ";", "{", "}", "[", "]");
$toEdit = str_replace($badChars, "_", $toEdit);
return $toEdit;
}