- Автор темы
- #1
Имееться форма мультизагрузки модуля вопрос-ответ под dle,ест класс загрузки в форме добавления материала:
[/spoil]
суть проблемы в том что не грузит на фтп в директорию ни файлы,ни картинки,второй файл инициализатор загрузки:
[spoil]
выскакивает ошибка загрузки,без вывода видих ошибок даже в дебагере ошибок лисы
PHP:
var SWFUpload;
if (SWFUpload == undefined) {
SWFUpload = function (a) {
this.initSWFUpload(a)
}
}
SWFUpload.prototype.initSWFUpload = function (b) {
try {
this.customSettings = {};
this.settings = b;
this.eventQueue = [];
this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
this.movieElement = null;
SWFUpload.instances[this.movieName] = this;
this.initSettings();
this.loadFlash();
this.displayDebugInfo()
} catch (a) {
delete SWFUpload.instances[this.movieName];
throw a
}
};
SWFUpload.instances = {};
SWFUpload.movieCount = 0;
SWFUpload.version = "2.2.0 2009-03-25";
SWFUpload.QUEUE_ERROR = {
QUEUE_LIMIT_EXCEEDED: -100,
FILE_EXCEEDS_SIZE_LIMIT: -110,
ZERO_BYTE_FILE: -120,
INVALID_FILETYPE: -130
};
SWFUpload.UPLOAD_ERROR = {
HTTP_ERROR: -200,
MISSING_UPLOAD_URL: -210,
IO_ERROR: -220,
SECURITY_ERROR: -230,
UPLOAD_LIMIT_EXCEEDED: -240,
UPLOAD_FAILED: -250,
SPECIFIED_FILE_ID_NOT_FOUND: -260,
FILE_VALIDATION_FAILED: -270,
FILE_CANCELLED: -280,
UPLOAD_STOPPED: -290
};
SWFUpload.FILE_STATUS = {
QUEUED: -1,
IN_PROGRESS: -2,
ERROR: -3,
COMPLETE: -4,
CANCELLED: -5
};
SWFUpload.BUTTON_ACTION = {
SELECT_FILE: -100,
SELECT_FILES: -110,
START_UPLOAD: -120
};
SWFUpload.CURSOR = {
ARROW: -1,
HAND: -2
};
SWFUpload.WINDOW_MODE = {
WINDOW: "window",
TRANSPARENT: "transparent",
OPAQUE: "opaque"
};
SWFUpload.completeURL = function (a) {
if (typeof (a) !== "string" || a == "" || a.match(/^https?:\/\//i) || a.match(/^\//)) {
return a
}
var c = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
var b = window.location.pathname.lastIndexOf("/");
if (b <= 0) {
path = "/"
} else {
path = window.location.pathname.substr(0, b) + "/"
}
return path + a
};
SWFUpload.prototype.initSettings = function () {
this.ensureDefault = function (b, a) {
this.settings[b] = (this.settings[b] == undefined) ? a : this.settings[b]
};
this.ensureDefault("upload_url", "");
this.ensureDefault("preserve_relative_urls", false);
this.ensureDefault("file_post_name", "Filedata");
this.ensureDefault("post_params", {});
this.ensureDefault("use_query_string", false);
this.ensureDefault("requeue_on_error", false);
this.ensureDefault("http_success", []);
this.ensureDefault("assume_success_timeout", 0);
this.ensureDefault("file_types", "*.*");
this.ensureDefault("file_types_description", "All Files");
this.ensureDefault("file_size_limit", 0);
this.ensureDefault("file_upload_limit", 0);
this.ensureDefault("file_queue_limit", 0);
this.ensureDefault("flash_url", "swfupload.swf");
this.ensureDefault("prevent_swf_caching", true);
this.ensureDefault("button_image_url", "");
this.ensureDefault("button_width", 1);
this.ensureDefault("button_height", 1);
this.ensureDefault("button_text", "");
this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
this.ensureDefault("button_text_top_padding", 0);
this.ensureDefault("button_text_left_padding", 0);
this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
this.ensureDefault("button_disabled", false);
this.ensureDefault("button_placeholder_id", "");
this.ensureDefault("button_placeholder", null);
this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
this.ensureDefault("debug", false);
this.settings.debug_enabled = this.settings.debug;
this.settings.return_upload_start_handler = this.returnUploadStart;
this.ensureDefault("swfupload_loaded_handler", null);
this.ensureDefault("file_dialog_start_handler", null);
this.ensureDefault("file_queued_handler", null);
this.ensureDefault("file_queue_error_handler", null);
this.ensureDefault("file_dialog_complete_handler", null);
this.ensureDefault("upload_start_handler", null);
this.ensureDefault("upload_progress_handler", null);
this.ensureDefault("upload_error_handler", null);
this.ensureDefault("upload_success_handler", null);
this.ensureDefault("upload_complete_handler", null);
this.ensureDefault("debug_handler", this.debugMessage);
this.ensureDefault("custom_settings", {});
this.customSettings = this.settings.custom_settings;
if ( !! this.settings.prevent_swf_caching) {
this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime()
}
if (!this.settings.preserve_relative_urls) {
this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url)
}
delete this.ensureDefault
};
SWFUpload.prototype.loadFlash = function () {
var a, b;
if (document.getElementById(this.movieName) !== null) {
throw "ID " + this.movieName + " is already in use. The Flash Object could not be added"
}
a = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
if (a == undefined) {
throw "Could not find the placeholder element: " + this.settings.button_placeholder_id
}
b = document.createElement("div");
b.innerHTML = this.getFlashHTML();
a.parentNode.replaceChild(b.firstChild, a);
if (window[this.movieName] == undefined) {
window[this.movieName] = this.getMovieElement()
}
};
SWFUpload.prototype.getFlashHTML = function () {
return ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">', '<param name="wmode" value="', this.settings.button_window_mode, '" />', '<param name="movie" value="', this.settings.flash_url, '" />', '<param name="quality" value="high" />', '<param name="menu" value="false" />', '<param name="allowScriptAccess" value="always" />', '<param name="flashvars" value="' + this.getFlashVars() + '" />', "</object>"].join("")
};
SWFUpload.prototype.getFlashVars = function () {
var b = this.buildParamString();
var a = this.settings.http_success.join(",");
return ["movieName=", encodeURIComponent(this.movieName), "&uploadURL=", encodeURIComponent(this.settings.upload_url), "&useQueryString=", encodeURIComponent(this.settings.use_query_string), "&requeueOnError=", encodeURIComponent(this.settings.requeue_on_error), "&httpSuccess=", encodeURIComponent(a), "&assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout), "&params=", encodeURIComponent(b), "&filePostName=", encodeURIComponent(this.settings.file_post_name), "&fileTypes=", encodeURIComponent(this.settings.file_types), "&fileTypesDescription=", encodeURIComponent(this.settings.file_types_description), "&fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit), "&fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit), "&fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit), "&debugEnabled=", encodeURIComponent(this.settings.debug_enabled), "&buttonImageURL=", encodeURIComponent(this.settings.button_image_url), "&buttonWidth=", encodeURIComponent(this.settings.button_width), "&buttonHeight=", encodeURIComponent(this.settings.button_height), "&buttonText=", encodeURIComponent(this.settings.button_text), "&buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding), "&buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding), "&buttonTextStyle=", encodeURIComponent(this.settings.button_text_style), "&buttonAction=", encodeURIComponent(this.settings.button_action), "&buttonDisabled=", encodeURIComponent(this.settings.button_disabled), "&buttonCursor=", encodeURIComponent(this.settings.button_cursor)].join("")
};
SWFUpload.prototype.getMovieElement = function () {
if (this.movieElement == undefined) {
this.movieElement = document.getElementById(this.movieName)
}
if (this.movieElement === null) {
throw "Could not find Flash element"
}
return this.movieElement
};
SWFUpload.prototype.buildParamString = function () {
var c = this.settings.post_params;
var b = [];
if (typeof (c) === "object") {
for (var a in c) {
if (c.hasOwnProperty(a)) {
b.push(encodeURIComponent(a.toString()) + "=" + encodeURIComponent(c[a].toString()))
}
}
}
return b.join("&")
};
SWFUpload.prototype.destroy = function () {
try {
this.cancelUpload(null, false);
var a = null;
a = this.getMovieElement();
if (a && typeof (a.CallFunction) === "unknown") {
for (var c in a) {
try {
if (typeof (a[c]) === "function") {
a[c] = null
}
} catch (e) {}
}
try {
a.parentNode.removeChild(a)
} catch (b) {}
}
window[this.movieName] = null;
SWFUpload.instances[this.movieName] = null;
delete SWFUpload.instances[this.movieName];
this.movieElement = null;
this.settings = null;
this.customSettings = null;
this.eventQueue = null;
this.movieName = null;
return true
} catch (d) {
return false
}
};
SWFUpload.prototype.displayDebugInfo = function () {
this.debug(["---SWFUpload Instance Info---\n", "Version: ", SWFUpload.version, "\n", "Movie Name: ", this.movieName, "\n", "Settings:\n", "\t", "upload_url: ", this.settings.upload_url, "\n", "\t", "flash_url: ", this.settings.flash_url, "\n", "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n", "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n", "\t", "http_success: ", this.settings.http_success.join(", "), "\n", "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n", "\t", "file_post_name: ", this.settings.file_post_name, "\n", "\t", "post_params: ", this.settings.post_params.toString(), "\n", "\t", "file_types: ", this.settings.file_types, "\n", "\t", "file_types_description: ", this.settings.file_types_description, "\n", "\t", "file_size_limit: ", this.settings.file_size_limit, "\n", "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n", "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n", "\t", "debug: ", this.settings.debug.toString(), "\n", "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n", "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n", "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n", "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n", "\t", "button_width: ", this.settings.button_width.toString(), "\n", "\t", "button_height: ", this.settings.button_height.toString(), "\n", "\t", "button_text: ", this.settings.button_text.toString(), "\n", "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n", "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n", "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n", "\t", "button_action: ", this.settings.button_action.toString(), "\n", "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n", "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n", "Event Handlers:\n", "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n", "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n", "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n", "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n", "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n", "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n", "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n", "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n", "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n", "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"].join(""))
};
SWFUpload.prototype.addSetting = function (b, c, a) {
if (c == undefined) {
return (this.settings[b] = a)
} else {
return (this.settings[b] = c)
}
};
SWFUpload.prototype.getSetting = function (a) {
if (this.settings[a] != undefined) {
return this.settings[a]
}
return ""
};
SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
argumentArray = argumentArray || [];
var movieElement = this.getMovieElement();
var returnValue, returnString;
try {
returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + "</invoke>");
returnValue = eval(returnString)
} catch (ex) {
throw "Call to " + functionName + " failed"
}
if (returnValue != undefined && typeof returnValue.post === "object") {
returnValue = this.unescapeFilePostParams(returnValue)
}
return returnValue
};
SWFUpload.prototype.selectFile = function () {
this.callFlash("SelectFile")
};
SWFUpload.prototype.selectFiles = function () {
this.callFlash("SelectFiles")
};
SWFUpload.prototype.startUpload = function (a) {
this.callFlash("StartUpload", [a])
};
SWFUpload.prototype.cancelUpload = function (a, b) {
if (b !== false) {
b = true
}
this.callFlash("CancelUpload", [a, b])
};
SWFUpload.prototype.stopUpload = function () {
this.callFlash("StopUpload")
};
SWFUpload.prototype.getStats = function () {
return this.callFlash("GetStats")
};
SWFUpload.prototype.setStats = function (a) {
this.callFlash("SetStats", [a])
};
SWFUpload.prototype.getFile = function (a) {
if (typeof (a) === "number") {
return this.callFlash("GetFileByIndex", [a])
} else {
return this.callFlash("GetFile", [a])
}
};
SWFUpload.prototype.addFileParam = function (a, b, c) {
return this.callFlash("AddFileParam", [a, b, c])
};
SWFUpload.prototype.removeFileParam = function (a, b) {
this.callFlash("RemoveFileParam", [a, b])
};
SWFUpload.prototype.setUploadURL = function (a) {
this.settings.upload_url = a.toString();
this.callFlash("SetUploadURL", [a])
};
SWFUpload.prototype.setPostParams = function (a) {
this.settings.post_params = a;
this.callFlash("SetPostParams", [a])
};
SWFUpload.prototype.addPostParam = function (a, b) {
this.settings.post_params[a] = b;
this.callFlash("SetPostParams", [this.settings.post_params])
};
SWFUpload.prototype.removePostParam = function (a) {
delete this.settings.post_params[a];
this.callFlash("SetPostParams", [this.settings.post_params])
};
SWFUpload.prototype.setFileTypes = function (a, b) {
this.settings.file_types = a;
this.settings.file_types_description = b;
this.callFlash("SetFileTypes", [a, b])
};
SWFUpload.prototype.setFileSizeLimit = function (a) {
this.settings.file_size_limit = a;
this.callFlash("SetFileSizeLimit", [a])
};
SWFUpload.prototype.setFileUploadLimit = function (a) {
this.settings.file_upload_limit = a;
this.callFlash("SetFileUploadLimit", [a])
};
SWFUpload.prototype.setFileQueueLimit = function (a) {
this.settings.file_queue_limit = a;
this.callFlash("SetFileQueueLimit", [a])
};
SWFUpload.prototype.setFilePostName = function (a) {
this.settings.file_post_name = a;
this.callFlash("SetFilePostName", [a])
};
SWFUpload.prototype.setUseQueryString = function (a) {
this.settings.use_query_string = a;
this.callFlash("SetUseQueryString", [a])
};
SWFUpload.prototype.setRequeueOnError = function (a) {
this.settings.requeue_on_error = a;
this.callFlash("SetRequeueOnError", [a])
};
SWFUpload.prototype.setHTTPSuccess = function (a) {
if (typeof a === "string") {
a = a.replace(" ", "").split(",")
}
this.settings.http_success = a;
this.callFlash("SetHTTPSuccess", [a])
};
SWFUpload.prototype.setAssumeSuccessTimeout = function (a) {
this.settings.assume_success_timeout = a;
this.callFlash("SetAssumeSuccessTimeout", [a])
};
SWFUpload.prototype.setDebugEnabled = function (a) {
this.settings.debug_enabled = a;
this.callFlash("SetDebugEnabled", [a])
};
SWFUpload.prototype.setButtonImageURL = function (a) {
if (a == undefined) {
a = ""
}
this.settings.button_image_url = a;
this.callFlash("SetButtonImageURL", [a])
};
SWFUpload.prototype.setButtonDimensions = function (c, a) {
this.settings.button_width = c;
this.settings.button_height = a;
var b = this.getMovieElement();
if (b != undefined) {
b.style.width = c + "px";
b.style.height = a + "px"
}
this.callFlash("SetButtonDimensions", [c, a])
};
SWFUpload.prototype.setButtonText = function (a) {
this.settings.button_text = a;
this.callFlash("SetButtonText", [a])
};
SWFUpload.prototype.setButtonTextPadding = function (b, a) {
this.settings.button_text_top_padding = a;
this.settings.button_text_left_padding = b;
this.callFlash("SetButtonTextPadding", [b, a])
};
SWFUpload.prototype.setButtonTextStyle = function (a) {
this.settings.button_text_style = a;
this.callFlash("SetButtonTextStyle", [a])
};
SWFUpload.prototype.setButtonDisabled = function (a) {
this.settings.button_disabled = a;
this.callFlash("SetButtonDisabled", [a])
};
SWFUpload.prototype.setButtonAction = function (a) {
this.settings.button_action = a;
this.callFlash("SetButtonAction", [a])
};
SWFUpload.prototype.setButtonCursor = function (a) {
this.settings.button_cursor = a;
this.callFlash("SetButtonCursor", [a])
};
SWFUpload.prototype.queueEvent = function (b, c) {
if (c == undefined) {
c = []
} else {
if (!(c instanceof Array)) {
c = [c]
}
}
var a = this;
if (typeof this.settings[b] === "function") {
this.eventQueue.push(function () {
this.settings[b].apply(this, c)
});
setTimeout(function () {
a.executeNextEvent()
}, 0)
} else {
if (this.settings[b] !== null) {
throw "Event handler " + b + " is unknown or is not a function"
}
}
};
SWFUpload.prototype.executeNextEvent = function () {
var a = this.eventQueue ? this.eventQueue.shift() : null;
if (typeof (a) === "function") {
a.apply(this)
}
};
SWFUpload.prototype.unescapeFilePostParams = function (c) {
var e = /[$]([0-9a-f]{4})/i;
var f = {};
var d;
if (c != undefined) {
for (var a in c.post) {
if (c.post.hasOwnProperty(a)) {
d = a;
var b;
while ((b = e.exec(d)) !== null) {
d = d.replace(b[0], String.fromCharCode(parseInt("0x" + b[1], 16)))
}
f[d] = c.post[a]
}
}
c.post = f
}
return c
};
SWFUpload.prototype.testExternalInterface = function () {
try {
return this.callFlash("TestExternalInterface")
} catch (a) {
return false
}
};
SWFUpload.prototype.flashReady = function () {
var a = this.getMovieElement();
if (!a) {
this.debug("Flash called back ready but the flash movie can't be found.");
return
}
this.cleanUp(a);
this.queueEvent("swfupload_loaded_handler")
};
SWFUpload.prototype.cleanUp = function (a) {
try {
if (this.movieElement && typeof (a.CallFunction) === "unknown") {
this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
for (var c in a) {
try {
if (typeof (a[c]) === "function") {
a[c] = null
}
} catch (b) {}
}
}
} catch (d) {}
window.__flash__removeCallback = function (e, f) {
try {
if (e) {
e[f] = null
}
} catch (g) {}
}
};
SWFUpload.prototype.fileDialogStart = function () {
this.queueEvent("file_dialog_start_handler")
};
SWFUpload.prototype.fileQueued = function (a) {
a = this.unescapeFilePostParams(a);
this.queueEvent("file_queued_handler", a)
};
SWFUpload.prototype.fileQueueError = function (a, c, b) {
a = this.unescapeFilePostParams(a);
this.queueEvent("file_queue_error_handler", [a, c, b])
};
SWFUpload.prototype.fileDialogComplete = function (b, c, a) {
this.queueEvent("file_dialog_complete_handler", [b, c, a])
};
SWFUpload.prototype.uploadStart = function (a) {
a = this.unescapeFilePostParams(a);
this.queueEvent("return_upload_start_handler", a)
};
SWFUpload.prototype.returnUploadStart = function (a) {
var b;
if (typeof this.settings.upload_start_handler === "function") {
a = this.unescapeFilePostParams(a);
b = this.settings.upload_start_handler.call(this, a)
} else {
if (this.settings.upload_start_handler != undefined) {
throw "upload_start_handler must be a function"
}
} if (b === undefined) {
b = true
}
b = !! b;
this.callFlash("ReturnUploadStart", [b])
};
SWFUpload.prototype.uploadProgress = function (a, c, b) {
a = this.unescapeFilePostParams(a);
this.queueEvent("upload_progress_handler", [a, c, b])
};
SWFUpload.prototype.uploadError = function (a, c, b) {
a = this.unescapeFilePostParams(a);
this.queueEvent("upload_error_handler", [a, c, b])
};
SWFUpload.prototype.uploadSuccess = function (b, a, c) {
b = this.unescapeFilePostParams(b);
this.queueEvent("upload_success_handler", [b, a, c])
};
SWFUpload.prototype.uploadComplete = function (a) {
a = this.unescapeFilePostParams(a);
this.queueEvent("upload_complete_handler", a)
};
SWFUpload.prototype.debug = function (a) {
this.queueEvent("debug_handler", a)
};
SWFUpload.prototype.debugMessage = function (c) {
if (this.settings.debug) {
var a, d = [];
if (typeof c === "object" && typeof c.name === "string" && typeof c.message === "string") {
for (var b in c) {
if (c.hasOwnProperty(b)) {
d.push(b + ": " + c[b])
}
}
a = d.join("\n") || "";
d = a.split("\n");
a = "EXCEPTION: " + d.join("\nEXCEPTION: ");
SWFUpload.Console.writeLine(a)
} else {
SWFUpload.Console.writeLine(c)
}
}
};
SWFUpload.Console = {};
SWFUpload.Console.writeLine = function (d) {
var b, a;
try {
b = document.getElementById("SWFUpload_Console");
if (!b) {
a = document.createElement("form");
document.getElementsByTagName("body")[0].appendChild(a);
b = document.createElement("textarea");
b.id = "SWFUpload_Console";
b.style.fontFamily = "monospace";
b.setAttribute("wrap", "off");
b.wrap = "off";
b.style.overflow = "auto";
b.style.width = "700px";
b.style.height = "350px";
b.style.margin = "5px";
a.appendChild(b)
}
b.value += d + "\n";
b.scrollTop = b.scrollHeight - b.clientHeight
} catch (c) {
alert("Exception: " + c.name + " Message: " + c.message)
}
};
if (jQuery)(function (jQuery) {
jQuery.extend(jQuery.fn, {
uploadify: function (options, swfUploadOptions) {
jQuery(this).each(function () {
var clone = jQuery(this).clone();
var settings = jQuery.extend({
id: jQuery(this).attr('id'),
swf: '/uploadify/uploadify.swf',
uploader: '/ajax/files.uploader.php',
auto: true,
buttonClass: '',
buttonCursor: 'hand',
buttonImage: "",
buttonText: '',
cancelImage: '',
checkExisting: false,
debug: false,
fileObjName: 'Filedata',
fileSizeLimit: 0,
fileTypeDesc: 'All Files',
fileTypeExts: '*.*',
height: 30,
method: 'post',
multi: false,
queueID: false,
queueSizeLimit: 10,
removeCompleted: false,
removeTimeout: 10,
requeueErrors: true,
postData: {},
preventCaching: true,
progressData: 'percentage',
successTimeout: 30,
transparent: true,
uploadLimit: 50,
uploaderType: 'flash',
width: 130,
skipDefault: [],
onClearQueue: function () {},
onDialogOpen: function () {},
onDialogClose: function () {},
onInit: function () {},
onQueueComplete: function () {},
onSelectError: function () {},
onSelect: function () {},
onSWFReady: function () {},
onUploadCancel: function () {},
onUploadComplete: function () {},
onUploadError: function () {},
onUploadProgress: function () {},
onUploadStart: function () {}
}, options);
var swfUploadSettings = {
assume_success_timeout: settings.successTimeout,
button_placeholder_id: settings.id,
button_image_url: settings.buttonImage,
button_width: settings.width,
button_height: settings.height,
button_text: null,
button_text_style: null,
button_text_top_padding: 0,
button_text_left_padding: 0,
button_action: (settings.multi ? SWFUpload.BUTTON_ACTION.SELECT_FILES : SWFUpload.BUTTON_ACTION.SELECT_FILE),
button_disabled: false,
button_cursor: (settings.buttonCursor == 'arrow' ? SWFUpload.CURSOR.ARROW : SWFUpload.CURSOR.HAND),
button_window_mode: (settings.transparent && !settings.buttonImage ? SWFUpload.WINDOW_MODE.TRANSPARENT : SWFUpload.WINDOW_MODE.OPAQUE),
debug: settings.debug,
requeue_on_error: settings.requeueErrors,
file_post_name: settings.fileObjName,
file_size_limit: settings.fileSizeLimit,
file_types: settings.fileTypeExts,
file_types_description: settings.fileTypeDesc,
file_queue_limit: settings.queueSizeLimit,
file_upload_limit: settings.uploadLimit,
flash_url: settings.swf,
prevent_swf_caching: settings.preventCaching,
post_params: settings.postData,
upload_url: settings.uploader,
use_query_string: (settings.method == 'get'),
file_dialog_complete_handler: onDialogClose,
file_dialog_start_handler: onDialogOpen,
file_queued_handler: onSelect,
file_queue_error_handler: onSelectError,
swfupload_loaded_handler: onSWFReady,
upload_complete_handler: onUploadComplete,
upload_error_handler: onUploadError,
upload_progress_handler: onUploadProgress,
upload_start_handler: onUploadStart,
upload_success_handler: onUploadSuccess
}
if (swfUploadOptions) {
swfUploadSettings = jQuery.extend(swfUploadSettings, swfUploadOptions);
}
swfUploadSettings = jQuery.extend(swfUploadSettings, settings);
window['uploadify_' + settings.id] = new SWFUpload(swfUploadSettings);
var swfuploadify = window['uploadify_' + settings.id];
swfuploadify.original = clone;
var wrapper = jQuery('<div />', {
id: settings.id,
'class': 'uploadify',
css: {
'height': settings.height + 'px',
'position': 'relative',
'width': settings.width + 'px'
}
});
jQuery('#' + swfuploadify.movieName).wrap(wrapper);
if (!settings.queueID) {
var queue = jQuery('<div />', {
id: settings.id + '_queue',
'class': 'uploadifyQueue'
});
jQuery('#' + settings.id).after(queue);
swfuploadify.settings.queueID = settings.queueID = settings.id + '_queue';
}
swfuploadify.queue = {
files: {},
filesSelected: 0,
filesQueued: 0,
filesReplaced: 0,
filesCancelled: 0,
filesErrored: 0,
averageSpeed: 0,
queueLength: 0,
queueSize: 0,
uploadSize: 0,
queueBytesUploaded: 0,
uploadQueue: [],
errorMsg: 'Some files were not added to the queue:'
};
if (!settings.buttonImage) {
var button = jQuery('<div />', {
id: settings.id + '_button',
'class': 'uploadifyButton ' + settings.buttonClass,
html: '<span class="uploadifyButtonText">' + settings.buttonText + '</span>'
});
jQuery('#' + settings.id).append(button);
jQuery('#' + swfuploadify.movieName).css({
position: 'absolute',
'z-index': 1
});
} else {
jQuery('#' + swfuploadify.movieName).addClass(settings.buttonClass);
}
function onSWFReady() {
if (swfuploadify.settings.onSWFReady) swfuploadify.settings.onSWFReady();
}
function onDialogClose(filesSelected, filesQueued, queueLength) {
swfuploadify.setButtonDisabled(0);
var stats = swfuploadify.getStats();
swfuploadify.queue.filesErrored = filesSelected - filesQueued;
swfuploadify.queue.filesSelected = filesSelected;
swfuploadify.queue.filesQueued = filesQueued - swfuploadify.queue.filesCancelled;
swfuploadify.queue.queueLength = queueLength;
if (jQuery.inArray('onDialogClose', swfuploadify.settings.skipDefault) < 0) {
if (swfuploadify.queue.filesErrored > 0) {
alert(swfuploadify.queue.errorMsg);
}
}
if (swfuploadify.settings.onDialogClose) swfuploadify.settings.onDialogClose(swfuploadify.queue);
if (swfuploadify.settings.auto) jQuery('#' + swfuploadify.settings.id).uploadifyUpload('*');
}
function onDialogOpen() {
swfuploadify.setButtonDisabled(1);
swfuploadify.queue.errorMsg = 'Вы выбрали слишком много файлов для загрузки';
swfuploadify.queue.filesReplaced = 0;
swfuploadify.queue.filesCancelled = 0;
if (swfuploadify.settings.onDialogOpen) swfuploadify.settings.onDialogOpen();
}
function onSelect(file) {
if (jQuery.inArray('onSelect', swfuploadify.settings.skipDefault) < 0) {
var queuedFile = {};
for (var n in swfuploadify.queue.files) {
queuedFile = swfuploadify.queue.files[n];
if (queuedFile.name == file.name) {
var replaceQueueItem = confirm('Файл "' + file.name + '" уже готов к загрузке.\nХотите заменить уже выбравнный файл?');
if (!replaceQueueItem) {
swfuploadify.cancelUpload(file.id);
swfuploadify.queue.filesCancelled++;
return false;
} else {
jQuery('#' + queuedFile.id).remove();
swfuploadify.cancelUpload(queuedFile.id);
swfuploadify.queue.filesReplaced++;
}
}
}
var fileSize = Math.round(file.size / 1024);
var suffix = 'KB';
if (fileSize > 1000) {
fileSize = Math.round(fileSize / 1000);
suffix = 'MB';
}
var fileSizeParts = fileSize.toString().split('.');
fileSize = fileSizeParts[0];
if (fileSizeParts.length > 1) {
fileSize += '.' + fileSizeParts[1].substr(0, 2);
}
fileSize += suffix;
var fileName = file.name;
jQuery('#' + swfuploadify.settings.queueID).append('<div id="' + file.id + '" class="uploadifyQueueItem">\
<div class="cancel">\
<a href="javascript:jQuery(\'#' + swfuploadify.settings.id + '\').uploadifyCancel(\'' + file.id + '\')"><img src="' + swfuploadify.settings.cancelImage + '" border="0" /></a>\
</div>\
<span class="fileName">' + fileName + ' (' + fileSize + ')</span><span class="data"></span>\
<div class="uploadifyProgress">\
<div class="uploadifyProgressBar"><!--Progress Bar--></div>\
</div>\
</div>');
swfuploadify.queue.queueSize += file.size;
}
swfuploadify.queue.files[file.id] = file;
if (swfuploadify.settings.onSelect) {
swfuploadify.settings.onSelect(file);
}
}
function declOfNum(number, titles) {
cases = [2, 0, 1, 1, 1, 2];
return titles[(number % 100 > 4 && number % 100 < 20) ? 2 : cases[(number % 10 < 5) ? number % 10 : 5]];
}
function onSelectError(file, errorCode, errorMsg) {
if (jQuery.inArray('onSelectError', swfuploadify.settings.skipDefault) < 0) {
switch (errorCode) {
case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
if (swfuploadify.settings.queueSizeLimit > errorMsg) {
var fileTXT = declOfNum(errorMsg, ['файл', 'файла', 'файлов']);
swfuploadify.queue.errorMsg += '\nВы можете загрузить еще ' + errorMsg + ' ' + fileTXT + '.';
} else {
var fileTXT = declOfNum(swfuploadify.settings.queueSizeLimit, ['файл', 'файла', 'файлов']);
swfuploadify.queue.errorMsg += '\nВы можете выбрать еще ' + swfuploadify.settings.queueSizeLimit + ' ' + fileTXT + '.';
}
break;
case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
swfuploadify.queue.errorMsg += '\nФайл "' + file.name + '" превышает допустимый размер ' + swfuploadify.settings.fileSizeLimit + '.';
break;
case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
swfuploadify.queue.errorMsg += '\nФайл "' + file.name + '" пустой.';
break;
case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
swfuploadify.queue.errorMsg += '\nФайл "' + file.name + '" имеет не правильное описание. Доступное описание для файлов (' + swfuploadify.settings.fileTypeDesc + ').';
break;
}
}
if (errorCode != SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
delete swfuploadify.queue.files[file.id];
}
if (swfuploadify.settings.onSelectError) swfuploadify.settings.onSelectError(file, errorCode, errorMsg);
}
function onQueueComplete() {
var stats = swfuploadify.getStats();
if (swfuploadify.settings.onQueueComplete) swfuploadify.settings.onQueueComplete(stats);
}
function onUploadComplete(file) {
var stats = swfuploadify.getStats();
swfuploadify.queue.queueLength = stats.files_queued;
if (swfuploadify.queue.uploadQueue[0] == '*') {
if (swfuploadify.queue.queueLength > 0) {
swfuploadify.startUpload();
} else {
swfuploadify.queue.uploadQueue = [];
if (swfuploadify.settings.onQueueComplete) swfuploadify.settings.onQueueComplete(stats);
}
} else {
if (swfuploadify.queue.uploadQueue.length > 0) {
swfuploadify.startUpload(swfuploadify.queue.uploadQueue.shift());
} else {
swfuploadify.queue.uploadQueue = [];
if (swfuploadify.settings.onQueueComplete) setting.onQueueComplete(stats);
}
}
if (jQuery.inArray('onUploadComplete', swfuploadify.settings.skipDefault) < 0) {
if (swfuploadify.settings.removeCompleted) {
switch (file.filestatus) {
case SWFUpload.FILE_STATUS.COMPLETE:
setTimeout(function () {
if (jQuery('#' + file.id)) {
swfuploadify.queue.queueSize -= file.size;
delete swfuploadify.queue.files[file.id]
jQuery('#' + file.id).fadeOut(500, function () {
jQuery(this).remove();
});
}
}, swfuploadify.settings.removeTimeout * 1000);
break;
case SWFUpload.FILE_STATUS.ERROR:
if (!swfuploadify.settings.requeueErrors) {
setTimeout(function () {
if (jQuery('#' + file.id)) {
swfuploadify.queue.queueSize -= file.size;
delete swfuploadify.queue.files[file.id];
jQuery('#' + file.id).fadeOut(500, function () {
jQuery(this).remove();
});
}
}, swfuploadify.settings.removeTimeout * 1000);
}
break;
}
}
}
if (swfuploadify.settings.onUploadComplete) swfuploadify.settings.onUploadComplete(file, swfuploadify.queue);
}
function onUploadError(file, errorCode, errorMsg) {
var errorString = 'Error';
if (errorCode != SWFUpload.UPLOAD_ERROR.FILE_CANCELLED && errorCode != SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED) {
jQuery('#' + file.id).addClass('uploadifyError');
}
jQuery('#' + file.id).find('.uploadifyProgressBar').css('width', '1px');
switch (errorCode) {
case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
errorString = 'HTTP Error (' + errorMsg + ')';
break;
case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
errorString = 'Missing Upload URL';
break;
case SWFUpload.UPLOAD_ERROR.IO_ERROR:
errorString = 'IO Error';
break;
case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
errorString = 'Security Error';
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
alert('The upload limit has been reached (' + errorMsg + ').');
errorString = 'Exceeds Upload Limit';
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
errorString = 'Failed';
break;
case SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND:
break;
case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
errorString = 'Validation Error';
break;
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
errorString = 'Cancelled';
swfuploadify.queue.queueSize -= file.size;
if (file.status == SWFUpload.FILE_STATUS.IN_PROGRESS || jQuery.inArray(file.id, swfuploadify.queue.uploadQueue) >= 0) {
swfuploadify.queue.uploadSize -= file.size;
}
delete swfuploadify.queue.files[file.id];
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
errorString = 'Stopped';
break;
}
if (errorCode != SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND && file.status != SWFUpload.FILE_STATUS.COMPLETE) {
jQuery('#' + file.id).find('.data').html(' - ' + errorString);
}
if (swfuploadify.settings.onUploadError) swfuploadify.settings.onUploadError(file, errorCode, errorMsg, errorString, swfuploadify.queue);
}
function onUploadProgress(file, fileBytesLoaded, fileTotalBytes) {
var timer = new Date();
var newTime = timer.getTime();
var lapsedTime = newTime - swfuploadify.timer;
swfuploadify.timer = newTime;
var lapsedBytes = fileBytesLoaded - swfuploadify.bytesLoaded;
swfuploadify.bytesLoaded = fileBytesLoaded;
var queueBytesLoaded = swfuploadify.queue.queueBytesUploaded + fileBytesLoaded;
var percentage = Math.round(fileBytesLoaded / fileTotalBytes * 100);
var mbs = 0;
var kbs = (lapsedBytes / 1024) / (lapsedTime / 1000);
kbs = Math.floor(kbs * 10) / 10;
if (swfuploadify.queue.averageSpeed > 0) {
swfuploadify.queue.averageSpeed = (swfuploadify.queue.averageSpeed + kbs) / 2;
} else {
swfuploadify.queue.averageSpeed = kbs;
}
if (kbs > 1000) {
mbs = (kbs * .001);
swfuploadify.queue.averageSpeed = mbs;
}
var suffix = 'KB/s';
if (mbs > 0) {
suffix = 'MB/s';
}
if (jQuery.inArray('onUploadProgress', swfuploadify.settings.skipDefault) < 0) {
if (swfuploadify.settings.progressData == 'percentage') {
jQuery('#' + file.id).find('.data').html(' - ' + percentage + '%');
} else if (swfuploadify.settings.progressData == 'speed') {
jQuery('#' + file.id).find('.data').html(' - ' + percentage + suffix);
}
jQuery('#' + file.id).find('.uploadifyProgressBar').css('width', percentage + '%');
}
if (swfuploadify.settings.onUploadProgress) swfuploadify.settings.onUploadProgress(file, fileBytesLoaded, fileTotalBytes, queueBytesLoaded, swfuploadify.queue.uploadSize);
}
function onUploadStart(file) {
var timer = new Date();
swfuploadify.timer = timer.getTime();
swfuploadify.bytesLoaded = 0;
if (swfuploadify.queue.uploadQueue.length == 0) {
swfuploadify.queue.uploadSize = file.size;
}
if (swfuploadify.settings.checkExisting !== false) {
jQuery.ajax({
type: 'POST',
async: false,
url: swfuploadify.settings.checkExisting,
data: {
filename: file.name
},
success: function (data) {
if (data == 1) {
var overwrite = confirm('Файл с именем "' + file.name + '" уже загружен на сервер.\nХотите заменить уже существующий файл?');
if (!overwrite) {
swfuploadify.cancelUpload(file.id);
jQuery('#' + file.id).remove();
if (swfuploadify.queue.uploadQueue.length > 0 && swfuploadify.queue.queueLength > 0) {
if (swfuploadify.queue.uploadQueue[0] == '*') {
swfuploadify.startUpload();
} else {
swfuploadify.startUpload(swfuploadify.queue.uploadQueue.shift());
}
}
}
}
}
});
}
if (swfuploadify.settings.onUploadStart) swfuploadify.settings.onUploadStart(file);
}
function onUploadSuccess(file, data, response) {
swfuploadify.queue.queueBytesUploaded += file.size;
if (swfuploadify.settings.onUploadSuccess) swfuploadify.settings.onUploadSuccess(file, data, response);
}
});
},
uploadifyCancel: function (fileID) {
var id = jQuery(this).selector.replace('#', '');
var swfuploadify = window['uploadify_' + id];
var delay = -1;
if (arguments[0]) {
if (arguments[0] == '*') {
jQuery('#' + swfuploadify.settings.queueID).find('.uploadifyQueueItem').each(function () {
delay++;
swfuploadify.cancelUpload(jQuery(this).attr('id'));
jQuery(this).delay(100 * delay).fadeOut(500, function () {
jQuery(this).remove();
});
});
swfuploadify.queue.queueSize = 0;
} else {
for (var n = 0; n < arguments.length; n++) {
swfuploadify.cancelUpload(arguments[n]);
jQuery('#' + arguments[n]).delay(100 * n).fadeOut(500, function () {
jQuery(this).remove();
});
}
}
} else {
jQuery('#' + swfuploadify.settings.queueID).find('.uploadifyQueueItem').get(0).fadeOut(500, function () {
jQuery(this).remove();
swfuploadify.cancelUpload(jQuery(this).attr('id'));
});
}
var stats = swfuploadify.getStats();
if (stats.files_queued == 0) {
$('#file_upload_startUpload').fadeOut('slow');
}
},
uploadifyDestroy: function () {
var id = jQuery(this).selector.replace('#', '');
var swfuploadify = window['uploadify_' + id];
swfuploadify.destroy();
jQuery('#' + id + '_queue').remove();
jQuery('#' + id).replaceWith(swfuploadify.original);
delete window['uploadify_' + id];
},
uploadifyDisable: function (isDisabled) {
var id = jQuery(this).selector.replace('#', '');
var swfuploadify = window['uploadify_' + id];
swfuploadify.setButtonDisabled(isDisabled);
},
uploadifySettings: function (name, value, resetObjects) {
var id = jQuery(this).selector.replace('#', '');
var swfuploadify = window['uploadify_' + id];
if (typeof (arguments[0]) == 'object') {
for (var n in value) {
setData(n, value[n]);
}
}
if (arguments.length == 1) {
return swfuploadify.settings[name];
} else {
setData(name, value, resetObjects);
}
function setData(settingName, settingValue, resetObjects) {
switch (settingName) {
case 'uploader':
swfuploadify.setUploadURL(settingValue);
break;
case 'postData':
if (!resetObjects) {
value = jQuery.extend(swfuploadify.settings.postData, settingValue);
}
swfuploadify.setPostParams(settingValue);
break;
case 'method':
if (settingValue == 'get') {
swfuploadify.setUseQueryString(true);
} else {
swfuploadify.setUseQueryString(false);
}
break;
case 'fileObjName':
swfuploadify.setFilePostName(settingValue);
break;
case 'fileTypeExts':
swfuploadify.setFileTypes(settingValue, swfuploadify.settings.fileTypeDesc);
break;
case 'fileTypeDesc':
swfuploadify.setFileTypes(swfuploadify.settings.fileTypeExts, settingValue);
break;
case 'fileSizeLimit':
swfuploadify.setFileSizeLimit(settingValue);
break;
case 'uploadLimit':
swfuploadify.setFileUploadLimit(settingValue);
break;
case 'queueSizeLimit':
swfuploadify.setFileQueueLimit(settingValue);
break;
case 'buttonImage':
jQuery('#' + swfuploadify.settings.id + '_button').remove();
swfuploadify.setButtonImageURL(settingValue);
break;
case 'buttonCursor':
if (settingValue == 'arrow') {
swfuploadify.setButtonCursor(SWFUpload.CURSOR.ARROW);
} else {
swfuploadify.setButtonCursor(SWFUpload.CURSOR.HAND);
}
break;
case 'buttonText':
jQuery('#' + swfuploadify.settings.id + '_button').find('.uploadifyButtonText').html(settingValue);
break;
case 'width':
swfuploadify.setButtonDimensions(settingValue, swfuploadify.settings.height);
break;
case 'height':
swfuploadify.setButtonDimensions(swfuploadify.settings.width, settingValue);
break;
case 'multi':
if (settingValue) {
swfuploadify.setButtonAction(SWFUpload.BUTTON_ACTION.SELECT_FILES);
} else {
swfuploadify.setButtonAction(SWFUpload.BUTTON_ACTION.SELECT_FILE);
}
break;
}
swfuploadify.settings[settingName] = value;
}
},
SetSuccessfulUploads: function (val) {
var id = jQuery(this).selector.replace('#', '');
var swfuploadify = window['uploadify_' + id];
var stats = swfuploadify.getStats();
stats.successful_uploads = val;
swfuploadify.setStats(stats);
},
SetErrorUploads: function () {
var id = jQuery(this).selector.replace('#', '');
var swfuploadify = window['uploadify_' + id];
var stats = swfuploadify.getStats();
stats.successful_uploads--;
swfuploadify.setStats(stats);
},
uploadifyAddPostParam: function (name, value) {
var id = jQuery(this).selector.replace('#', '');
var swfuploadify = window['uploadify_' + id];
swfuploadify.addPostParam(name, value);
},
uploadifyStop: function () {
var id = jQuery(this).selector.replace('#', '');
var swfuploadify = window['uploadify_' + id];
swfuploadify.stopUpload();
},
uploadifyUpload: function () {
var id = jQuery(this).selector.replace('#', '');
var swfuploadify = window['uploadify_' + id];
swfuploadify.queue.averageSpeed = 0;
swfuploadify.queue.uploadSize = 0;
swfuploadify.queue.bytesUploaded = 0;
swfuploadify.queue.uploadQueue = [];
if (arguments[0]) {
if (arguments[0] == '*') {
swfuploadify.queue.uploadSize = swfuploadify.queue.queueSize;
swfuploadify.queue.uploadQueue.push('*');
swfuploadify.startUpload();
} else {
for (var n = 0; n < arguments.length; n++) {
swfuploadify.queue.uploadSize += swfuploadify.queue.files[arguments[n]].size;
swfuploadify.queue.uploadQueue.push(arguments[n]);
}
swfuploadify.startUpload(swfuploadify.queue.uploadQueue.shift());
}
} else {
swfuploadify.startUpload();
}
}
})
})(jQuery);
function insertimage(selectedImage) {
imageAlign = $('#imageAlign').val();
if (imageAlign == 'center') {
finalImage = "[center][img]" + selectedImage + "[/img][/center]";
} else {
finalImage = "[img=" + imageAlign + "]" + selectedImage + "[/img]";
}
tinyMCE.execCommand('mceInsertContent', false, finalImage);
}
function insertthumb(selectedImage) {
imageAlign = $('#imageAlign').val();
if (imageAlign == 'center') {
finalImage = "[center][thumb]" + selectedImage + "[/thumb][/center]";
} else {
finalImage = "[thumb=" + imageAlign + "]" + selectedImage + "[/thumb]";
}
tinyMCE.execCommand('mceInsertContent', false, finalImage);
}
function insertfile(selectedFile) {
tinyMCE.execCommand('mceInsertContent', false, selectedFile);
}
function ckeck_uncheck_all(block_id, check_butt) {
if ($('#' + block_id + ' input[name=' + check_butt + ']').is(':checked')) {
$('#' + block_id + ' .files_content').find('input:checkbox').attr("checked", "checked");
} else {
$('#' + block_id + ' .files_content').find('input:checkbox').attr("checked", "");
}
}
function tag_disable() {
if ($('#make_thumb').attr('checked')) {
$('#img_settings').show();
} else {
$('#img_settings').hide();
}
}
function file_uploader(mod, area, post_id) {
$("#file_uploder").remove();
ShowLoading('');
$.post('/engine/modules/faq/admin/ajax/files.uploader.php', {
mod: mod,
area: area,
post_id: post_id
}, function (data) {
HideLoading('');
$("body").append(data);
$('#file_uploder').dialog({
autoOpen: true,
show: 'fade',
hide: 'fade',
width: 650
});
});
return false;
};
function file_descr(ID) {
if ($('#' + ID + '_descr_content').is(':visible')) {
$('#' + ID + '_descr_content').hide('slow');
$('#' + ID + '_descr_link').html(uploadify_show);
} else {
$('#' + ID + '_descr_content').show('slow');
$('#' + ID + '_descr_link').html(uploadify_hide);
}
}
function UploadifyDisable(ID, val) {
$('#' + ID).uploadifyDisable(val);
}
function UploadifyQFLimit(ID, val) {
$('#' + ID).uploadifySettings('uploadLimit', val);
$('#' + ID).uploadifySettings('queueSizeLimit', val);
}
function UploadifyStartUpload(ID) {
$('#' + ID).uploadifyUpload('*');
}
function uploadifyAllCancel(ID) {
$('#' + ID).uploadifyCancel('*');
}
function file_delete(mod, area, post_id, type) {
ShowLoading('');
var i = 0;
$('#' + type + '_all_check').attr('checked', '');
$('#' + type + '-delete').attr('disabled', 'disabled');
var arr_checkbox = new Array();
$('.' + type + '-checkbox:checked').each(function () {
arr_checkbox[i] = $(this).val();
i++;
});
if (i != 0) {
$.post('/engine/modules/faq/admin/ajax/files.uploader.php', {
mod: mod,
area: area,
post_id: post_id,
file_delete: 1,
type: type,
arr_checkbox: arr_checkbox
}, function (data) {
HideLoading('');
if (data.substring(0, 6) == 'ERROR:') {
$('#file_upload').SetErrorUploads();
jQuery('#' + file.id).find('.data').html(' - ' + uploadify_msg_error);
jQuery('#' + file.id).append(data);
jQuery('#' + file.id).addClass('uploadifyError');
$('#' + type + '-delete').removeAttr('disabled');
} else {
var data = data.split("|");
var i = 0;
$.each(data, function (index, post_id) {
$('#' + post_id).slideUp(1000);
$('#' + post_id).remove();
i++;
});
var file_uploaded = $("#divStatus").html();
var file_uploaded = parseInt(file_uploaded) - i;
$("#divStatus").html(file_uploaded);
$('#file_upload').SetSuccessfulUploads(file_uploaded);
$('#' + type + '-delete').removeAttr('disabled');
$('#uploadifyButtons').css({
visibility: "visible"
});
}
});
} else {
HideLoading('');
$('#' + type + '-delete').removeAttr('disabled');
alert(uploadify_error_delete);
}
}
function one_file_delete(mod, area, post_id, type, file_id) {
ShowLoading('');
var file_value = $("#uploadify_filevalue_" + file_id).val();
var arr_checkbox = new Array();
arr_checkbox[0] = file_value;
if (arr_checkbox[0]) {
$.post('/engine/modules/faq/admin/ajax/files.uploader.php', {
file_id: file_id,
mod: mod,
area: area,
post_id: post_id,
file_delete: 1,
type: type,
arr_checkbox: arr_checkbox
}, function (data) {
HideLoading('');
$('#uploadify_filevalue_' + file_id).val('');
if (data.substring(0, 6) == 'ERROR:') {
$('#' + file_id).SetErrorUploads();
$('#uploadify_queueID_' + file_id).find('.data').html(' - ' + uploadify_msg_error).find('.uploadifyQueueItem').addClass('uploadifyError').append(data);
} else {
$('#uploadify_queueID_' + file_id).find('.uploadifyQueueItem').remove();
if ($('#uploadify_block_' + file_id).is(':hidden')) {
$('#uploadify_load_id_' + file_id).show();
} else {
$('#uploadify_load_id_' + file_id).show();
$('#' + file_id + '_button').css({
visibility: "visible"
});
$('#' + file_id).uploadifyDisable(0);
$('#' + file_id).SetSuccessfulUploads(0);
}
if ($('#file_upload').is(':visible')) {
$('#' + data).slideUp(1000).remove();
var file_uploaded = parseInt($("#divStatus").html()) - 1;
$("#divStatus").html(file_uploaded);
$('#file_upload').SetSuccessfulUploads(file_uploaded);
$('#uploadifyButtons').css({
visibility: "visible"
});
}
}
});
}
};
суть проблемы в том что не грузит на фтп в директорию ни файлы,ни картинки,второй файл инициализатор загрузки:
[spoil]
PHP:
<?php
/*
=====================================================
Module FAQ for DataLife Engine
-----------------------------------------------------
author: RinX
email: rinx@inbox.ru
icq: 195444502
-----------------------------------------------------
Copyright (c) 2011
=====================================================
Данный код защищен авторскими правами
=====================================================
Файл: /engine/ucatalog/classes/files.uploader.php
-----------------------------------------------------
Назначение: Загрузчик файлов на сервер.
=====================================================
*/
if(!defined( 'DATALIFEENGINE')){die("Hacking attempt!");}
include_once ENGINE_DIR.'/classes/thumb.class.php';
class uc_files_uploader extends thumbnail{
var $file_prefix = ''; // Префикс будет добавлятся вначале имен всех файлов.
var $image_ext = array("gif", "jpg", "png", "jpeg");
var $video_ext = array('avi', 'mp4', 'wmv', 'mpg', 'flv', 'mp3', 'swf', 'm4v', 'm4a', 'mov', '3gp', 'f4v');
var $allowed_extensions = Array();
var $files_uploaded = 0;
var $stop = Array();
function uc_files_uploader($MOD_NAME, $TABLE_FILES, $config, $lang){
global $db, $member_id, $PHP_SELF;
$this->session_id = session_id();
$this->db = $db;
$this->author = $member_id['name'];
$this->MOD_NAME = $MOD_NAME;
$this->TABLE_FILES = $TABLE_FILES;
$this->config = $config;
$this->lang = $lang;
if($_REQUEST['area']){
$this->area = totranslit(stripslashes(trim($_REQUEST['area'])));
if(!in_Array($this->area, Array('category','questions'))){die('no area');}
}
$this->post_id = intval($_REQUEST['post_id']);
$this->WEB_ADMIN_DIR = WEB_ADMIN_DIR;
$this->WEB_CLASS_DIR = WEB_CLASS_DIR;
$this->PHP_SELF = $PHP_SELF;
$files_ext = explode(',', $this->config['files_type']);
$this->files_ext = $files_ext;
$this->img_dir_http = str_replace(ROOT_DIR , substr($this->config['http_home_url'], 0, strlen($this->config['http_home_url']) - 1), UPLOAD_DIR_IMAGE);
$this->file_dir_http = str_replace(ROOT_DIR , substr($this->config['http_home_url'], 0, strlen($this->config['http_home_url']) - 1), UPLOAD_DIR_FILES);
if($this->config['images_allow_cfg'] AND $_POST['file_upload']){
$this->config['allow_watermark'] = ($_POST['allow_watermark']) ? 1 : 0;
$this->config['make_thumb'] = ($_POST['make_thumb']) ? 1 : 0;
$max_image = explode ("x", $_POST['max_image']);
$this->config['max_image'] = (count($max_image) == 2) ? intval($max_image[0])."x".intval($max_image[1]) : intval($max_image[0]);
$this->config['t_seite'] = ($_POST['t_seite']) ? intval($_POST['t_seite']) : 0;
}
$this->max_file_size = str_replace( array ('M', 'm' ), '', @ini_get( 'upload_max_filesize' ) );
$this->max_file_size = formatsize( $this->max_file_size * 1024 * 1024 );
$this->seite_selected[$this->config['t_seite']] = 'selected="selected"';
$this->image_align[$this->config['image_align']] = 'selected="selected"';
}
function file_delete(){
$this->stop = 'ERROR:';
if(in_Array($_POST['type'], Array('image','video','files'))){
$this->type = $_POST['type'];
$this->db->query( "SELECT id, file_name, file_path, images, type FROM " . $this->TABLE_FILES . " WHERE type='".$this->type."' AND area='".$this->area."' AND author = '".$this->author."' AND post_id = '".$this->post_id."';");
while($row = $this->db->get_row()) {
if($this->type == 'image'){
$post_images = explode( "|||", $row['images'] );
sort($post_images); reset($post_images);
$i = 0;
foreach ($post_images as $image ) {
if(in_Array($image, $_POST['arr_checkbox'])) {
$url_image = explode( "/", $image );
if( count( $url_image ) == 2 ) {
$this->FOLDER_PREFIX = $url_image[0];
$this->new_file_name = $url_image[1];
} else {
$this->FOLDER_PREFIX = "";
$this->new_file_name = $url_image[0];
}
$this->img_dir_uppload = UPLOAD_DIR_IMAGE.$this->FOLDER_PREFIX."/";
unset( $post_images[$i] );
$this->hide_id[] = 'F-'.md5($image);
@unlink($this->img_dir_uppload.$this->new_file_name);
@unlink($this->img_dir_uppload."thumbs/".$this->new_file_name);
}
$i++;
}
}else{
if(in_Array($row['file_path'], $_POST['arr_checkbox'])){
$url_file = explode( "/", $row['file_path'] );
if(count( $url_file ) == 2 ){
$this->FOLDER_PREFIX = $url_file[0];
$this->new_file_name = $url_file[1];
} else{
$this->FOLDER_PREFIX = "";
$this->new_file_name = $url_file[0];
}
$this->file_name = $row['file_name'];
$this->file_id[] = $row['id'];
$this->hide_id[] = 'F-'.md5($row['file_path']);
$this->file_dir_uppload = UPLOAD_DIR_FILES.$this->FOLDER_PREFIX.'/';
@unlink($this->file_dir_uppload.$this->new_file_name);
}
}
}
$field_name = strtolower(totranslit($_POST['field_name']));
if($field_name != ""){
unset($_SESSION['onefileupload'][$this->post_id][$field_name]);
}
if($this->type == 'image'){
if(count($post_images)){
$this->db->query( "UPDATE " . $this->TABLE_FILES . " SET type='".$this->type."', images='".implode( "|||", $post_images )."' WHERE area='".$this->area."' AND type='".$this->type."' AND author = '".$this->author."' AND post_id = '".$this->post_id."';");
}else{
$this->db->query( "DELETE FROM " . $this->TABLE_FILES . " WHERE area='".$this->area."' AND type='".$this->type."' AND author = '".$this->author."' AND post_id = '".$this->post_id."';");
}
}else{
$this->file_id = (is_Array($this->file_id)) ? (count($this->file_id)==1) ? '='.$this->file_id[0] : "IN (".implode(',', $this->file_id).")" : '='.$this->file_id;
if($this->file_id != ""){
$this->db->query ("DELETE FROM " . $this->TABLE_FILES . " WHERE id ".$this->file_id);
}
}
$body = implode('|', $this->hide_id);
}else{
$this->stop .= "File type error \r\n";
}
if($this->stop != 'ERROR:'){
echo $this->stop;
}else{
echo $body;
}
exit();
}
function echo_multi_files_uploader(){
$files_content = $this->show_multi_files_upload();
$body .= $this->show_multi_JS();
$body .= $this->show_multi_form();
$body .= $files_content;
$body = '<div id="file_uploder" title="'.$this->lang['fileuploader'].'" style="display:none">'.$body.'</div>';
echo $body;
}
function file_upload(){
$this->db->query( "INSERT INTO " . $this->TABLE_FILES . " (area, type, author, post_id, date, file_path) values ('".$this->area."', '".$this->type."', '".$this->author."', '".$this->post_id."', '".$this->added_time."', '".$this->FOLDER_PREFIX."/".$this->new_file_name."')" );
$this->file_id = $this->db->insert_id();
@move_uploaded_file($this->file_tmp, $this->file_dir_uppload.$this->new_file_name) or die($this->lang['fileuploader_msg_error_3']);
if(@file_exists($this->file_dir_uppload.$this->new_file_name)){
@chmod($this->file_dir_uppload.$this->new_file_name, 0666 );
$field_name = strtolower(totranslit($_POST['field_name']));
if($field_name != ""){
$_SESSION['onefileupload'][$this->post_id][$field_name] = $this->FOLDER_PREFIX."/".$this->new_file_name;
}
}else{ die($this->lang['fileuploader_msg_error_3']); }
}
function image_upload(){
$post_images = ($this->images_uploaded == '') ? array () : explode( "|||", $this->images_uploaded);
$post_images[] = $this->FOLDER_PREFIX."/".$this->new_file_name;
if($this->images_uploaded != ''){
$this->db->query( "UPDATE " . $this->TABLE_FILES . " SET type='".$this->type."', images='".implode( "|||", $post_images )."' WHERE area='".$this->area."' AND type='".$this->type."' AND author = '".$this->author."' AND post_id = '".$this->post_id."';");
}else{
$this->db->query( "INSERT INTO " . $this->TABLE_FILES . " (area, type, images, author, post_id, date) values ('".$this->area."', '".$this->type."', '".implode( "|||", $post_images )."', '".$this->author."', '".$this->post_id."', '".$this->added_time."');" );
}
@move_uploaded_file($this->file_tmp, $this->img_dir_uppload.$this->new_file_name) or die($this->lang['fileuploader_msg_error_3']);
if(@file_exists($this->img_dir_uppload.$this->new_file_name)){
@chmod($this->img_dir_uppload.$this->new_file_name, 0666 );
$field_name = strtolower(totranslit($_POST['field_name']));
if($field_name != ""){
$_SESSION['onefileupload'][$this->post_id][$field_name] = $this->FOLDER_PREFIX."/".$this->new_file_name;
}
}else{ die($this->lang['fileuploader_msg_error_3']); }
$t_seite = ($this->config['t_seite']) ? $this->config['t_seite'] : 0;
if($this->config['make_thumb']){
$max_image = ($this->config['max_image'] != 0) ? $this->config['max_image'] : 0;
$this->thumbnail($this->img_dir_uppload.$this->new_file_name);
$this->jpeg_quality($this->config['jpeg_quality'] );
if ( $this->size_auto($max_image, $t_seite) ) {
$this->save($this->img_dir_uppload."thumbs/".$this->new_file_name );
if ( @file_exists($this->img_dir_uppload."thumbs/".$this->new_file_name ) ){
@chmod($this->img_dir_uppload."thumbs/".$this->new_file_name, 0666 );
}
}
}
$this->thumbnail($this->img_dir_uppload.$this->new_file_name);
$this->jpeg_quality($this->config['jpeg_quality'] );
if($this->config['allow_watermark']){
$this->insert_watermark($this->config['max_watermark']);
}
if($this->config['max_up_side'] != 0){
$this->size_auto($this->config['max_up_side']);
}
$this->save($this->img_dir_uppload.$this->new_file_name );
if (@file_exists($this->img_dir_uppload.$this->new_file_name ) ){
@chmod($this->img_dir_uppload.$this->new_file_name, 0666 );
}
}
function run_upload(){
$POST_MAX_SIZE = ini_get('post_max_size');
$unit = strtoupper(substr($POST_MAX_SIZE, -1));
$multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
header("HTTP/1.1 500 Internal Server Error");
exit(0);
}
$this->file_name = totranslit(convert_unicode($_FILES['Filedata']['name'], $this->config['charset']));
$this->file_tmp = $_FILES['Filedata']['tmp_name'];
$this->file_size = $_FILES['Filedata']['size'];
$this->file_error = $_FILES['Filedata']['error'];
$this->file_type = strtolower(totranslit(end(explode( ".", $this->file_name))));
$this->added_time = time() + ($this->config['date_adjust'] * 60);
$this->added_time = date ("Y-m-d H:i:s", $this->added_time);
if(in_Array($this->file_type, $this->image_ext)){
$this->type = 'image';
$this->check_file_error($this->image_ext);
$this->create_image_dir();
if(count($this->stop) == 0){
$this->image_upload();
}
}elseif(in_Array($this->file_type, $this->video_ext)){
$this->type = 'video';
$this->check_file_error($this->video_ext);
$this->create_file_dir();
if(count($this->stop) == 0){
$this->file_upload();
}
}elseif(in_Array($this->file_type, $this->files_ext)){
$this->type = 'files';
$this->check_file_error($this->files_ext);
$this->create_file_dir();
if(count($this->stop) == 0){
$this->file_upload();
}
}else{
$this->stop[] = $this->lang['fileuploader_msg_error_1'];
}
}
function upload(){
$this->run_upload();
if(count($this->stop) > 0){
$stop = iconv($this->config['charset'], "UTF-8", implode("<br />", $this->stop));
echo '<div class="msgError">'.$stop.'</div>';
exit(0);
}else{
echo iconv($this->config['charset'], "UTF-8", $this->get_file_html(1, 1));
exit();
}
}
function get_file_html($use_type=false, $display_none = false){
if($this->type == 'image'){
$img_info = @getimagesize($this->img_dir_uppload.$this->new_file_name);
$info_file = $img_info[0].'x'.$img_info[1];
if(file_exists($this->img_dir_uppload.'thumbs/'.$this->new_file_name)){
$thumb_img_info = @getimagesize($this->img_dir_uppload.'thumbs/'.$this->new_file_name);
$thumb_img_info = $thumb_img_info[0] + 50;
$insert_file = '<a class=maintitle href="javascript:insertthumb(\''.$this->img_dir_uppload_http.$this->new_file_name. '\')">'.$this->new_file_name.'</a>';
}else{
$insert_file = '<a class=maintitle href="javascript:insertimage(\''.$this->img_dir_uppload_http.$this->new_file_name.'\')">'.$this->new_file_name.'</a>';
}
$original_link = '[ <a class=maintitle href="javascript:insertimage(\''.$this->img_dir_uppload_http.$this->new_file_name .'\')">'.$this->lang['fileuploader_original'].'</a> ] ';
$show_file = $original_link.'[ <a class="maintitle" href="javascript:ShowBild(\''.$this->img_dir_uppload_http.$this->new_file_name.'\')">'.$this->lang['fileuploader_view'].'</a> ]';
}else if($this->type == 'video'){
$info_file = formatsize( @filesize($this->file_dir_uppload.$this->new_file_name));
if($this->file_type == 'mp3' ) {
$insert_file = '<a class="maintitle" href="javascript:insertfile(\'[audio='.$this->file_dir_uppload_http.$this->new_file_name.']\')">'.$this->new_file_name.'</a>';
} elseif ($this->file_type == 'swf') {
$insert_file = '<a class="maintitle" href="javascript:insertfile(\'[flash=425,264]'.$this->file_dir_uppload_http.$this->new_file_name.'[/flash]\')">'.$this->new_file_name.'</a>';
} else {
$insert_file = '<a class="maintitle" href="javascript:insertfile(\'[video='.$this->file_dir_uppload_http.$this->new_file_name.']\')">'.$this->new_file_name.'</a>';
}
$show_file = '<a class="maintitle" href="javascript:insertfile(\'[attachment='.$this->file_id.':'.$this->new_file_name.']\')">'.$this->lang['fileuploader_insertfile'].'</a>';
}else if($this->type == 'files'){
$info_file = formatsize( @filesize($this->file_dir_uppload.$this->new_file_name));
$insert_file = '<a class="maintitle" href="javascript:insertfile(\'[attachment='.$this->file_id.':'.$this->new_file_name.']\')">'.$this->new_file_name.'</a>';
}
$use_type = ($use_type) ? $this->type.'|'.$this->FOLDER_PREFIX."/".$this->new_file_name.'|' : false;
$display_none = ($display_none) ? ' style="display:none;"' : false;
$file_id = md5($this->FOLDER_PREFIX."/".$this->new_file_name);
return $use_type.'
<div'.$display_none.' id="F-'.$file_id.'" class="files-list">
<ul>
<li class="first">'.$insert_file.'</li>
<li><input type="checkbox" class="'.$this->type.'-checkbox" name="files['.$this->FOLDER_PREFIX."/".$this->new_file_name.']" value="'.$this->FOLDER_PREFIX."/".$this->new_file_name.'"></li>
<li>'.$info_file.'</li>
<li>'.$show_file.'</li>
</ul>
<div class="hr_mline"></div>
</div>';
}
function check_file_error($allowed_type){
$this->db->query( "SELECT id, images, type FROM " . $this->TABLE_FILES . " WHERE area='".$this->area."' AND author = '".$this->author."' AND post_id = '".$this->post_id."';");
while ( $row = $this->db->get_row()) {
if($row['images'] != '' AND $row['type'] == 'image'){
$this->images_uploaded = $row['images'];
$images_arr = explode( "|||", $row['images'] );
$this->files_uploaded = $this->files_uploaded + count($images_arr);
}else{
$this->files_uploaded++;
}
}
if($this->files_uploaded >= $this->config['max_upload_limit']){
$this->stop[] = $this->lang['fileuploader_msg_error_2'];
}
if( strpos ($this->file_type, "php" ) !== false ){$this->stop[] = $this->lang['fileuploader_msg_error_1'];}
if (!in_array($this->file_type, $allowed_type)) {
$this->stop[] = $this->lang['fileuploader_msg_error_1'];
} else if ($this->file_error > 0) {
switch ($this->file_error) {
case 1: $this->file_error = 'PHP Error: The uploaded file exceeds the upload_max_filesize directive in php.ini'; break;
case 2: $this->file_error = 'PHP Error: The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; break;
case 3: $this->file_error = 'PHP Error: The uploaded file was only partially uploaded'; break;
case 4: $this->file_error = 'PHP Error: No file was uploaded'; break;
case 5: $this->file_error = 'PHP Error: Missing a PHP temporary folder'; break;
case 6: $this->file_error = 'PHP Error: Failed to write file to disk'; break;
case 7: $this->file_error = 'PHP Error: File upload stopped by extension'; break;
default: $this->file_error = 'Unknown upload error'; break;
}
$this->stop[] = $this->file_error;
}
}
function create_image_dir(){
if (@ini_get( 'safe_mode' ) == 1){
$this->FOLDER_PREFIX;
}else{
$this->FOLDER_PREFIX = date( "Y-m" );
}
$this->img_dir_uppload = UPLOAD_DIR_IMAGE.$this->FOLDER_PREFIX."/";
$this->img_dir_uppload_http = str_replace(ROOT_DIR , substr($this->config['http_home_url'], 0, strlen($this->config['http_home_url']) - 1), UPLOAD_DIR_IMAGE).$this->FOLDER_PREFIX."/";
if(!is_dir(UPLOAD_DIR_IMAGE.$this->FOLDER_PREFIX)) {
@mkdir(UPLOAD_DIR_IMAGE.$this->FOLDER_PREFIX, 0777 );
@chmod(UPLOAD_DIR_IMAGE.$this->FOLDER_PREFIX, 0777 );
@mkdir(UPLOAD_DIR_IMAGE.$this->FOLDER_PREFIX."/thumbs", 0777 );
@chmod(UPLOAD_DIR_IMAGE.$this->FOLDER_PREFIX."/thumbs", 0777 );
$hta_file = $this->img_dir_uppload.'index.html';
@fopen($hta_file, 'w');
@fclose();
$hta_file = $this->img_dir_uppload.'thumbs/index.html';
@fopen($hta_file, 'w');
@fclose();
}
if(!is_dir(UPLOAD_DIR_IMAGE.$this->FOLDER_PREFIX )) {
$this->stop[] = $this->FOLDER_PREFIX.' cannot created.';
}
$file_name_arr = explode( ".", $this->file_name);
$type = end($file_name_arr);
$curr_key = key($file_name_arr);
unset($file_name_arr[$curr_key]);
$file_name = implode(".", $file_name_arr );
$file_suffix = '';
while ( file_exists($this->img_dir_uppload .$this->file_prefix.$file_name.$file_suffix.'.'.$type) ) {
$file_suffix++;
}
$this->new_file_name = $this->file_prefix.$file_name.$file_suffix.'.'.$type;
}
function create_file_dir(){
if (@ini_get( 'safe_mode' ) == 1){
$this->FOLDER_PREFIX;
}else{
$this->FOLDER_PREFIX = date( "Y-m" );
}
$this->file_dir_uppload = UPLOAD_DIR_FILES.$this->FOLDER_PREFIX.'/';
$this->file_dir_uppload_http = str_replace(ROOT_DIR , substr($this->config['http_home_url'], 0, strlen($this->config['http_home_url']) - 1), UPLOAD_DIR_FILES).$this->FOLDER_PREFIX."/";
if(!is_dir(UPLOAD_DIR_FILES.$this->FOLDER_PREFIX)) {
@mkdir(UPLOAD_DIR_FILES.$this->FOLDER_PREFIX, 0777 );
@chmod(UPLOAD_DIR_FILES.$this->FOLDER_PREFIX, 0777 );
$hta_file = $this->file_dir_uppload.'.htaccess';
if (!$handle = fopen($hta_file, 'w')) {
die($this->FOLDER_PREFIX.' no .htaccess');
}
$ext_video_hta = implode('|', $this->video_ext);
$hta_content = <<<TXT
<FilesMatch ".*">
Order allow,deny
Deny from all
</FilesMatch>
<FilesMatch "\.({$ext_video_hta})$|^$">
Order deny,allow
Allow from all
</FilesMatch>
TXT;
if (fwrite($handle, $hta_content) === FALSE) {
$this->stop[] = $this->FOLDER_PREFIX.' .htaccess not allowed';
}
fclose($handle);
}
if(!is_dir(UPLOAD_DIR_FILES.$this->FOLDER_PREFIX )) {
$this->stop[] = $this->FOLDER_PREFIX.' cannot created.';
}
$file_name_arr = explode( ".", $this->file_name);
$type = end($file_name_arr);
$curr_key = key($file_name_arr);
unset($file_name_arr[$curr_key]);
$file_name = implode(".", $file_name_arr );
$file_suffix = '';
while ( file_exists($this->file_dir_uppload .$this->file_prefix.$file_name.$file_suffix.'.'.$type) ) {
$file_suffix++;
}
$this->new_file_name = $this->file_prefix.$file_name.$file_suffix.'.'.$type;
}
function show_multi_form(){
$max_upload_limit = ($this->config['max_upload_limit'] > 0) ? $this->config['max_upload_limit'] : $this->lang['fileuploader_unlimited'];
$display_button = ($this->config['max_upload_limit'] == $this->files_uploaded) ? ' style="display:none"' : '';
$body .= <<<HTML
<form action='{$this->PHP_SELF}' method='post' id="uloadifyForm">
<fieldset class="UploadProgress">
<legend>{$this->lang['fileuploader_list_upload']}</legend>
<div id="UploadProgress"></div>
<input id="file_upload_startUpload" style="display:none;" type="button" class="buttons" value="{$this->lang['fileuploader_uploadfiles']}" onclick="UploadifyStartUpload('file_upload'); return false;" />
</fieldset>
<div class="file_uploaded">{$this->lang['fileuploader_file_uploaded']} <span id="divStatus">{$this->files_uploaded}</span></div>
<div class="max_upload_limit">
{$this->lang['fileuploader_max_upload_limit']} <span id="maxsize_file">{$max_upload_limit}</span>
</div>
<div class="maxsize_file">
{$this->lang['fileuploader_maxsize_file']} <b>{$this->max_file_size}</b>
</div>
<div id="uploadifyButtons">
<div class="uploadifyBlock-1 uploadifyColumn">
<input type="file" id="file_upload" name="file_upload" />
</div>
<div class="uploadifyBlock-2 uploadifyColumn">
<input type="button" class="buttons" value="{$this->lang['fileuploader_cancel']}" onclick="uploadifyAllCancel('file_upload'); return false;" />
</div>
<div style="clear:both"></div>
</div>
<div class="hr_line"></div>
HTML;
if($this->config['images_allow_cfg']){
if($this->config['allow_watermark']){
$body .= <<<HTML
<input type="checkbox" name="allow_watermark" value="yes" checked="checked" /> <label for="allow_watermark">{$this->lang['fileuploader_make_watermark']}</label>
HTML;
}
if($this->config['make_thumb']){
$body .= <<<HTML
<div style="height:25px;">
<input onClick="tag_disable()" type="checkbox" name="make_thumb" value="make_thumb" id="make_thumb" checked="checked" /> <label for="make_thumb">{$this->lang['fileuploader_make_thumb']}</label>
<span id="img_settings">{$this->lang['upload_max_image']} <input class="edit" type="text" name="max_image" id="max_image" size=9 value="{$this->config['max_image']}" /> px <select name="t_seite" id="t_seite" ><option value="0" {$this->seite_selected[0]}>{$this->lang['fileuploader_seite_1']}</option><option value="1" {$this->seite_selected[1]}>{$this->lang['fileuploader_seite_2']}</option><option value="2" {$this->seite_selected[2]}>{$this->lang['fileuploader_seite_3']}</option></select></span>
</div>
HTML;
}
}
$body .= '<div class="hr_line"></div></form>';
return $body;
}
function show_multi_files_upload(){
$this->db->query( "SELECT id, file_name, file_path, images, type FROM " . $this->TABLE_FILES . " WHERE area='".$this->area."' AND author = '".$this->author."' AND post_id = '".$this->post_id."';");
$images = Array();
$files = Array();
$video = Array();
while($row = $this->db->get_row()) {
$this->type = $row['type'];
if($this->type == 'image'){
$post_images = explode( "|||", $row['images'] );
sort($post_images); reset($post_images);
foreach ($post_images as $image ) {
$url_image = explode( "/", $image );
if( count( $url_image ) == 2 ) {
$this->FOLDER_PREFIX = $url_image[0];
$this->new_file_name = $url_image[1];
} else {
$this->FOLDER_PREFIX = "";
$this->new_file_name = $url_image[0];
}
$this->img_dir_uppload = UPLOAD_DIR_IMAGE.$this->FOLDER_PREFIX."/";
$this->img_dir_uppload_http = $this->img_dir_http.$this->FOLDER_PREFIX."/";
if(@file_exists(UPLOAD_DIR_IMAGE.$this->FOLDER_PREFIX."/".$this->new_file_name) AND $this->new_file_name != ""){
$images_display = true;
$this->files_uploaded++;
$images[] = $this->get_file_html();
}
}
}else if($this->type == 'video' OR $this->type == 'files'){
$url_file = explode( "/", $row['file_path'] );
if(count( $url_file ) == 2 ){
$this->FOLDER_PREFIX = $url_file[0];
$this->new_file_name = $url_file[1];
} else{
$this->FOLDER_PREFIX = "";
$this->new_file_name = $url_file[0];
}
$this->file_name = $row['file_name'];
$this->file_id = $row['id'];
$this->file_dir_uppload = UPLOAD_DIR_FILES.$this->FOLDER_PREFIX.'/';
$this->file_dir_uppload_http = $this->file_dir_http.$this->FOLDER_PREFIX."/";
if(@file_exists(UPLOAD_DIR_FILES.$this->FOLDER_PREFIX."/".$this->new_file_name) AND $this->new_file_name !=""){
if($this->type == 'video'){
$this->file_type = end(explode( ".", $this->new_file_name));
$this->files_uploaded++;
$video[] = $this->get_file_html();
$video_display = true;
}else{
$this->files_uploaded++;
$files[] = $this->get_file_html();
$files_display = true;
}
}
}
}
$images_display = (!$images_display) ? ' style="display:none;"' : '';
$video_display = (!$video_display) ? ' style="display:none;"' : '';
$files_display = (!$files_display) ? ' style="display:none;"' : '';
return <<<HTML
<form action='{$this->URL_MOD}' method='post' name="delfiles" id="delfiles">
<div id="image-block"{$images_display}>
{$this->show_files_block('image', $images)}
</div>
<div id="video-block"{$video_display}>
{$this->show_files_block('video', $video)}
</div>
<div id="files-block"{$files_display}>
{$this->show_files_block('files', $files)}
</div>
</form>
HTML;
}
function show_files_block($type, $files_content){
$files_content = (count($files_content)) ? implode('', $files_content) : '';
if($type == 'image'){
$imageAlign = '
<div id="imageAlign-block">
'.$this->lang['fileuploader_imgAlign'].':
<select name="imageAlign" id="imageAlign">
<option value="none" '.$this->image_align[0].'>'.$this->lang['fileuploader_imgAlign_no'].'</option>
<option value="left" '.$this->image_align['left'].'>'.$this->lang['fileuploader_imgAlign_left'].'</option>
<option value="right" '.$this->image_align['right'].'>'.$this->lang['fileuploader_imgAlign_right'].'</option>
<option value="center" '.$this->image_align['center'].'>'.$this->lang['fileuploader_imgAlign_center'].'</option>
</select>
</div>
<div class="hr_mline"></div>';
}
return <<<HTML
<table width="100%">
<tr>
<td style="background:#EFEFEF; padding-left:10px;"><div class="navigation">{$this->lang['fileuploader_'.$type.'_list']}</div></td>
<td style="background:#EFEFEF; width:26px;"><input type="checkbox" name="{$type}_all_check" id="{$type}_all_check" title="{$this->lang['fileuploader_select_all']}" onclick="ckeck_uncheck_all('{$type}-block', '{$type}_all_check')">
</tr>
</table>
<div class="unterline"></div>
{$imageAlign}
<div class="files_content">{$files_content}</div>
<div style="text-align:right; margin:2px 0 5px 0;"><input class="edit" value="{$this->lang['fileuploader_files_delete']}" type="submit" onclick="file_delete('{$this->MOD_NAME}', '{$this->area}', '{$this->post_id}', '{$type}'); return false;" id="{$type}-delete" /></div>
<div class="unterline"></div>
HTML;
}
function show_multi_JS(){
if(in_Array('images', $this->config['allow_upload'])){
$this->allowed_extensions = $this->image_ext;
}
if(in_Array('files', $this->config['allow_upload'])){
$this->allowed_extensions = array_merge($this->allowed_extensions, $this->files_ext);
}
if(in_Array('video', $this->config['allow_upload'])){
$this->allowed_extensions = array_merge($this->allowed_extensions, $this->video_ext);
}
$this->allowed_extensions = "*.".implode( ";*.", $this->allowed_extensions );
return <<<HTML
<script type="text/javascript">
function ShowBild(sPicURL) {
window.open('{$this->config['http_home_url']}engine/modules/imagepreview.php?image='+sPicURL, '', 'resizable=1,HEIGHT=200,WIDTH=200, scrollbars=yes');
}
$(document).ready(function() {
var max_upload_limit = {$this->config['max_upload_limit']};
var files_uploaded_start = {$this->files_uploaded};
$("#file_upload").uploadify({
'swf' : '{$this->WEB_CLASS_DIR}/uploadify/uploadify.swf',
'uploader' : '{$this->WEB_ADMIN_DIR}/ajax/files.uploader.php',
'cancelImage' : '{$this->WEB_CLASS_DIR}/uploadify/cancel.png',
'queueID' : 'UploadProgress',
'buttonText' : '{$this->lang['fileuploader_addfiles']}',
'postData' : {"PHPSESSID" : "{$this->session_id}", "file_upload" : "1", "area":"{$this->area}", "post_id":"{$this->post_id}"},
'queueSizeLimit' : '{$this->config['max_upload_limit']}',
'uploadLimit' : '{$this->config['max_upload_limit']}',
'fileSizeLimit' : '{$this->max_file_size}',
'fileTypeExts' : "{$this->allowed_extensions}",
'multi' : true,
'removeCompleted' : true,
'auto' : false,
'onSWFReady' : function() {
$('#file_upload').SetSuccessfulUploads(files_uploaded_start);
if(files_uploaded_start >= max_upload_limit){
$('#uploadifyButtons').css({visibility: "hidden"});
}
},
'onSelect' : function(file) {
$('#uloadifyForm input:text, #uloadifyForm input:checkbox:checked, #uloadifyForm input:radio:checked, #uloadifyForm select').each(function(){
if($(this).attr('type')!="button"){
$('#file_upload').uploadifyAddPostParam($(this).attr("name"), $(this).val());
}
});
$('#file_upload_startUpload').fadeIn('slow');
jQuery('#' + file.id).find('.data').html(' - {$this->lang['fileuploader_msg_queue']}');
},
'onUploadSuccess' : function(file, data) {
jQuery('#' + file.id).find('.cancel').fadeOut('slow');
var data = data.split("|");
var type = data[0];
if(type == 'image' || type == 'files' || type == 'video'){
jQuery('#' + file.id).find('.data').html(' - {$this->lang['fileuploader_msg_complete']}');
var id = type + '-block';
$('#' + id).slideDown();
$('#' + id + " .files_content").append(data[2]);
$('#' + id + " .files_content").find("div").slideDown();
var status = $("#divStatus").html();
status = parseInt(status) + 1;
$("#divStatus").html(status);
jQuery('#' + file.id).addClass('uploadifyCompleted');
}else{
$('#file_upload').SetErrorUploads();
jQuery('#' + file.id).find('.data').html(' - {$this->lang['fileuploader_msg_error']}');
jQuery('#' + file.id).append(data[2]);
jQuery('#' + file.id).addClass('uploadifyError');
}
},
'onQueueComplete' : function(stats) {
$('#file_upload_startUpload').fadeOut('slow');
if(max_upload_limit == stats.successful_uploads){
$('#uploadifyButtons').css({visibility: "hidden"});
}else{
$('#uploadifyButtons').css({visibility: "visible"});
}
}
});
});
</script>
HTML;
}
function show_one_file_uploader($field_name, $file_value, $type, $allowed_extensions){
$ID = 'xfield_'.$field_name;
$this->allowed_extensions = "*.".implode( ";*.", $allowed_extensions);
$file_show = $file_value[1];
$file_value = $file_value[0];
if($_SESSION['onefileupload'][$this->post_id][$field_name]){
$file_value = $_SESSION['onefileupload'][$this->post_id][$field_name];
if($type == 'image'){
$url_image = explode( "/", $file_value);
if( count( $url_image ) == 2 ) {
$FOLDER_PREFIX = $url_image[0];
$file_name = $url_image[1];
} else {
$FOLDER_PREFIX = "";
$file_name = $url_image[0];
}
$img_dir_uppload = UPLOAD_DIR_IMAGE.$FOLDER_PREFIX."/";
if(file_exists($img_dir_uppload."thumbs/".$file_name)){
$file_show = faq_build_thumb($this->img_dir_http.$file_value, $this->img_dir_http.$FOLDER_PREFIX."/thumbs/".$file_name);
}else{
$file_show = faq_build_image($this->img_dir_http.$file_value);
}
}else if($type == 'video'){
$file_show = faq_build_video($this->file_dir_http.$file_value);
}else if($type == 'files'){
$file_show = faq_build_file($file_value);
}
}
if($file_show){
$file_show = <<<HTML
<div><a id="{$ID}_descr_link" onclick="file_descr('{$ID}'); return false;" href="#">{$this->lang['fileuploader_descr_show']}</a></div>
<div id="{$ID}_descr_content" style="display:none">
{$file_show}
</div>
HTML;
}
if(!file_exists(UPLOAD_DIR_IMAGE.$file_value) AND $type == 'image'){
$file_value = '';
unset($_SESSION['onefileupload'][$this->post_id][$field_name]);
}else if(($type == 'video' OR $type == 'files') AND !file_exists(UPLOAD_DIR_FILES.$file_value)){
$file_value = '';
unset($_SESSION['onefileupload'][$this->post_id][$field_name]);
}
$JS = <<<HTML
function uploadify_load_{$ID}(){
$('#uploadify_load_id_{$ID}').hide();
$("#{$ID}").uploadify({
'swf' : '{$this->WEB_CLASS_DIR}/uploadify/uploadify.swf',
'uploader' : '{$this->WEB_ADMIN_DIR}/ajax/files.uploader.php',
'cancelImage' : '{$this->WEB_CLASS_DIR}/uploadify/cancel.png',
'queueID' : 'uploadify_queueID_{$ID}',
'buttonText' : '{$this->lang['fileuploader_'.$type.'upload']}',
'postData' : {"field_name": "{$field_name}", "PHPSESSID" : "{$this->session_id}", "file_upload" : "1", "area":"{$this->area}", "post_id":"{$this->post_id}"},
'queueSizeLimit' : 1,
'uploadLimit' : 1,
'width' : 170,
'fileSizeLimit' : '{$this->max_file_size}',
'fileTypeExts' : "{$this->allowed_extensions}",
'onUploadStart' : function(file, data) {
$('#{$ID}_button').css({visibility: "hidden"});
$('#uploadify_load_id_{$ID}').hide();
},
'onUploadSuccess' : function(file, data) {
var data = data.split("|");
var type = data[0];
var filevalue = data[1];
var response = data[2];
if(type == 'image' || type == 'files' || type == 'video'){
$('#uploadify_filevalue_{$ID}').val(filevalue);
$('#' + file.id).addClass('uploadifyCompleted').find('.data').html(' - {$this->lang['fileuploader_msg_complete']}');
$('#' + file.id).find('.uploadifyProgress').hide('slow');
$('#' + file.id).find('.cancel a').attr("href", "javascript:one_file_delete('{$this->MOD_NAME}', '{$this->area}', '{$this->post_id}', '{$type}', '{$ID}')");
$('#{$ID}').uploadifyDisable(1);
if($('#file_upload').is(':visible')){
var id = type + '-block';
$('#' + id).slideDown().find(".files_content").append(response).find("div").slideDown();
var file_uploaded = parseInt($("#divStatus").html()) + 1;
$("#divStatus").html(file_uploaded);
if(file_uploaded == max_upload_limit){
$('#uploadifyButtons').css({visibility: "hidden"});
}else{
$('#uploadifyButtons').css({visibility: "visible"});
}
$('#file_upload').SetSuccessfulUploads(file_uploaded);
}
}else{
if($('#file_upload').is(':visible')){
$('#file_upload').SetErrorUploads();
}
$('#{$ID}').SetErrorUploads();
$('#' + file.id).find('.cancel').hide();
$('#' + file.id).find('.data').html(' - {$this->lang['fileuploader_msg_error']}');
$('#' + file.id).append(data[0]).addClass('uploadifyError');
}
}
});
$('#uploadify_block_{$ID}').show();
$('#uploadify_load_id_{$ID}').show();
}
HTML;
$body = <<<HTML
<div class="uploadifyOneFileBlock" id="uploadify_{$ID}">
<div class="FileOneUpload-column-1">
<div id="uploadify_queueID_{$ID}">
HTML;
if($file_value){
$file_name = strtolower(totranslit(end(explode( "/", $file_value))));
$style_button = 'style="display:none;"';
$body .= <<<HTML
<div class="uploadifyQueueItem uploadifyCompleted">
<div class="cancel"><a href="javascript:one_file_delete('{$this->MOD_NAME}', '{$this->area}', '{$this->post_id}', '{$type}', '{$ID}')")"><img border="0" src="{$this->WEB_CLASS_DIR}/uploadify/cancel.png"></a></div>
<span class="fileName">{$file_name}</span>
{$file_show}
</div>
HTML;
}
$body .= <<<HTML
</div>
</div>
<div class="FileOneUpload-column-2">
<input title="{$this->lang['fileuploader_load_refresh']}" type="button" {$style_button} class="button-refresh" id="uploadify_load_id_{$ID}" onclick="javascript:uploadify_load_{$ID}();" value=" " />
<div id="uploadify_block_{$ID}" style="float:left; padding-top:5px;display:none"><input type="file" id="{$ID}" name="{$ID}" /></div>
<input type="hidden" id="uploadify_filevalue_{$ID}" name="xfield[{$field_name}]" value="{$file_value}" />
</div>
<div style="clear:both;"></div>
</div>
HTML;
return Array('js' => $JS, 'body' => $body);
}
}
?>