Actionscript:
System.security.allowDomain("http://" + _root.tdomain + "/");
import flash.net.FileReferenceList;
import flash.net.FileReference;
import flash.external.ExternalInterface;
import flash.external.*;
/* Main variables */
var session_photos = _root.ph;
var how_much_you_can_upload = 0;
var selected_photos; // container for selected photos
var inside_photo_num = 0; // for photo in_array selection
var created_elements = _root.ph;
var for_js_num = _root.ph;
/* Functions & settings for javascript<->flash conversation */
var methodName:String = "addtoflash";
var instance:Object = null;
var method:Function = addnewphotonumber;
var wasSuccessful:Boolean = ExternalInterface.addCallback(methodName, instance, method);
function addnewphotonumber() {
session_photos--;
created_elements--;
for_js_num--;
}
/* Javascript hide and show flash button functions */
function block(){getURL("Javascript: blocking();");}
function unblock(){getURL("Javascript:unblocking();");}
/* Creating HTML platform function */
var result = false;
/* Uploading */
function uploadthis(photos:Array) {
if(!photos[inside_photo_num].upload("http://" + _root.tdomain + "/upload.php?PHPSESSID=" + _root.phpsessionid))
{
getURL("Javascript:error_uploading();");
}
}
/* Flash button(applet) options and bindings */
var fileTypes:Array = new Array();
var imageTypes:Object = new Object();
imageTypes.description = "Images (*.jpg)";
imageTypes.extension = "*.jpg;";
fileTypes.push(imageTypes);
var fileListener:Object = new Object();
var btnListener:Object = new Object();
btnListener.click = function(eventObj:Object)
{
var fileRef:FileReferenceList = new FileReferenceList();
fileRef.addListener(fileListener);
fileRef.browse(fileTypes);
}
uploadButton.addEventListener("click", btnListener);
/* Listeners */
fileListener.onSelect = function(fileRefList:FileReferenceList):Void
{
// reseting values
inside_photo_num = 0;
var list:Array = fileRefList.fileList;
var item:FileReference;
// PHP photo counter
how_much_you_can_upload = 3 - session_photos;
if(list.length > how_much_you_can_upload)
{
getURL("Javascript:howmuch=" + how_much_you_can_upload + ";list_length=" + list.length + ";limit_reached();");
return;
}
// if session variable isn't yet refreshed, we check inner counter
if(created_elements >= 3)
{
getURL("Javascript:limit_reached();");
return;
}
selected_photos = list;
for(var i:Number = 0; i < list.length; i++)
{
how_much_you_can_upload--;
item = list[i];
trace("name: " + item.name);
trace(item.addListener(this));
if((item.size / 1024) > 5000) {getURL("Javascript:size_limit_reached();");return;}
}
result = false;
setTimeout(block,500);
/* Increment number for new HTML container and pass it to javascript, after javascript returns true and we start uploading */
for_js_num++;
if(ExternalInterface.call("create_platform",for_js_num))
{
uploadthis(selected_photos);
}
}
fileListener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void
{
getURL("Javascript:files_process(" + bytesLoaded + "," + bytesTotal + "," + for_js_num + ");");
}
fileListener.onComplete = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void
{
inside_photo_num++;
var sendvar_lv:LoadVars = new LoadVars();
var loadvar_lv:LoadVars = new LoadVars();
loadvar_lv.onLoad = function(success:Boolean){
if(loadvar_lv.failed == 1) {
getURL("Javascript:type_failed();");
return;
}
getURL("Javascript:filelinks='" + loadvar_lv.json + "';fullname='" + loadvar_lv.fullname + "';completed(" + for_js_num + ");");
created_elements++;
if((inside_photo_num + 1) > selected_photos.length) {setTimeout(unblock,1000);return;} // don't create empty containers anymore
if(created_elements >= 3) {return;}
result = false;
/* Increment number for new HTML container and pass it to javascript, after javascript returns true and we start uploading */
for_js_num++;
if(ExternalInterface.call("create_platform",for_js_num))
{
uploadthis(selected_photos);
}
}
sendvar_lv.getnum = true;
sendvar_lv.PHPSESSID = _root.phpsessionid;
sendvar_lv.sendAndLoad("http://" + _root.tdomain + "/upload.php",loadvar_lv,"POST");
}
fileListener.onCancel = function(file:FileReference):Void
{
}
fileListener.onOpen = function(file:FileReference):Void
{
}
fileListener.onHTTPError = function(file:FileReference, httpError:Number):Void
{
getURL("Javascript:http_error(" + httpError + ");");
}
fileListener.onSecurityError = function(file:FileReference, errorString:String):Void
{
getURL("Javascript:security_error(" + errorString + ");");
}
fileListener.onIOError = function(file:FileReference):Void
{
getURL("Javascript:io_error();");
selected_photos[inside_photo_num].cancel();
uploadthis(selected_photos);
}
<PARAM name="allowScriptAccess" value="always">
<PARAM name="swliveconnect" value="true">
<PARAM name="movie" value="http://www.localh.com/fileref.swf?ph=0&phpsessionid=8mirsjsd75v6vk583vkus50qbb2djsp6&tdomain=www.localh.com">
<PARAM name="wmode" value="opaque">
<PARAM name="quality" value="high">
<PARAM name="bgcolor" value="#ffffff">
<EMBED swliveconnect="true" wmode="opaque" src="http://www.localh.com/fileref.swf?ph=0&phpsessionid=8mirsjsd75v6vk583vkus50qbb2djsp6&tdomain=www.localh.com" quality="high" bgcolor="#ffffff" width="100" height="22" name="fileref" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></EMBED>
My uploading speed is 40kb/sec
Getting flash error while uploading photos bigger than 500kb and getting no error while uploading photos less than 100-500kb~.
My friend has 8mbit uploading speed and has no errors even while uploading 3.2mb photos and more.
How to fix this problem?
I have tried to re-upload on IO error trigger, but it stops at the same place.
Any solution regarding this error?
By the way, i was watching process via debugging proxy and figured out, that responce headers doesn't come at all on this IO error.
And sometimes shows socket error.
If need, i will post serverside php script as well. But it stops at
if(isset($_FILES['Filedata']))
{
so it won't help :) as all processing comes after this check.