`
huxiaojun_198213
  • 浏览: 105565 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

swfupload指南

阅读更多
SWFUpload

SWFUpload最初是由Vinterwebb.se开发的一个客户端的上传工具. 它结合了FLASH和JavaScript的功能,以提供一种超越了传统的浏览器中<input type="file" />标签提供的文件上传功能。

SWFUpload提供的主要特性:

在文件选择对话框中能够选择多个文件,即可以同时上传多个文件
类似AJAX的页面无刷新上传
提供上传进度的事件回调,实时显示上传进度
采用命名空间类以兼容其它JS库(如jQuery、Prototype等等)
对FLASH 9和FLASH 10播放器的支持(V2.2.0版本废弃了对Flash 8的支持)

SWFUpload不同于其他基于Flash构建的上传工具,它有着优雅的代码设计,开发者可以利用XHTML、CSS和 JavaScript来随心所欲的定制它在浏览器下的外观;它还提供了一组简明的JavaScript事件,借助它们开发者可以方便的在文件上传过程中更新页面内容来营造各种动态效果。

遗憾的是,为了能够触发文件浏览对话窗口,Flash Player 10迫使我们不得不在Flash影片中放入一个按钮。SWFUpload仍然允许用户通过JavaScript脚本来覆盖文本。

SWFUpload v2

SWFUpload v2包含了许多新的高级特性来改善稳定性,并提供一套有用的插件来解决FlashPlayer中的存在的bug。新特性包括:

兼容了Flash Player 10的安全机制
在文件上传的同时能够发送额外的POST数据
针对每一个文件上传发送POST/GET数据
一整套的事件回调机制
动态修改实例设置
接收服务端返回的数据
非取消形式的停止文件上传
自定义上传的顺序
支持单文件、多文件的文件的选择
可定制文件队列大小,文件上传数量和文件大小的限制
适当处理0字节的文件
支持预上传验证事件
解决(Work-arounds)Flash和浏览器中的bugs

概述

HTML上传

标准的HTML上传input表单字段为用户提供一个文本框和按钮来选择文件,选择的文件是通过form表单提交的。整个文件必须在下一个页面显示之前,完成上传,这种方式不能对选择的文件做预先的文件校验(如文件大小或有效的扩展名校验),且当文件上传时,用户获得的可用的反馈信息很少。

传统的HTML上传模式十分简单,几乎所有浏览器都支持它。

SWFUpload

SWFUpload使用Flash影片来处理文件的选择和上传,由其中的定制Button来激活高级文件选择对话框。此文件选择对话框通过配置可以允许用户选择一个单独的文件或者是多个文件。 选择的文件类型可以通过配置来进行限制,以使用户只能选择指定的适当的文件,例如*.jgp;*.gif。

一旦选定了文件,所有的文件都会经过验证和入列。当上传文件的时候,由开发人员预定义的Javascript事件会被触发以便来更新页面中的UI,并实时提供提供上传状态和错误信息。

上传文件的提交和它页面的其它部分、表单是独立的。每个文件都是单独上传的,这就保证了服务端脚本能够更容易地处理单个文件。虽然Flash提供了上传服务,但是页面没有必要提交或者重新载入。相比于标准的HTML Form,SWFUpload的使用方式更像是AJAX程序,页面中的Form将会脱离于文件上传而进行单独处理。

入门

SWFUpload并不是拖放式的上传控件,它需要JavaScript和DOM的知识。一些可用的演示展示了它能够完成什么事情以及它是如何完成这些常见的任务。

SWFUpload由4部分组成:

1.初始化和设置(Javascript)
2.JavaScript 库: SWFUpload.js
3.Flash控制元素: swfupload.swf
4.事件处理器(JavaScript)

使用SWFUpload遇到的多数问题是由不正确地设置或者定义了糟糕的处理事件, Flash/Browser Bugs, 或服务端配置而引起的。

初始化和设置

SWFpload必须在页面中初始化,一般可以在window.onload事件中完成此操作。它的构造函数需要一个Object类型的设置对象。 这个设置对象一般是一个直接定义的Object类型变量,直接传递给SWFUpload的构造函数。

初始化的SWFUpload对象的引用需要保留下来,因为当显示文件选择对话框和启动文件上传的时候需要这个实例的引用。

示例:用直接定义的Object类型变量设置初始化SWFUpload对象

var swfu;

window.onload = function () {
swfu = new SWFUpload({
upload_url : "http://www.swfupload.org/upload.php",
flash_url : "http://www.swfupload.org/swfupload.swf",
file_size_limit : "20 MB"
});
};

示例: 用存储在变量中的设置对象来初始化SWFUpload

var swfu;

window.onload = function () {
var settings_object = {
upload_url : "http://www.swfupload.org/upload.php",
flash_url : "http://www.swfupload.org/swfupload.swf",
file_size_limit : "20 MB"
};

swfu = new SWFUpload(settings_object);
};

JavaScript 库

该JavaScript库文件(swfupload.js)应该包含在用户需要上传功能的页面中。

一旦SWFUpload创建完成,开发人员就可以用其专有的函数来控制此实例。

示例: 添加SWFUpload.js到页面中

<script type="text/javascript" src="http://www.swfupload.org/swfupload.js"></script>

示例: 使用其必须的设置来初始化SWFUpload

var swfu = new SWFUpload({
upload_url : "http://www.swfupload.org/upload.php",
flash_url : "http://www.swfupload.org/swfupload_f9.swf",
button_placeholder_id : "spanSWFUploadButton"
});

Flash 控制元素

SWFUpload JavaScript 库可以动态加载Flash控制元素 (swfupload.swf).

Flash控制元素的文件位置必须在初始化的时候在SWFUpload设置对象中定义。

Flash控制元素是一个很小的用于处理文件浏览,验证和上传的Flash影片。它在页面中,它展现为一个按钮,并通过与Javascript通信来通知浏览器上传状态和其它事件。

The Event Handlers

Developers must create a set of JavaScript functions that handle SWFUpload events. These functions are called as different important events occur.

By handling the SWFUpload events developers can provide feedback regarding the upload progress, error messages, and upload completion. Developers should not overwrite functions stored in SWFUpload.prototype. Instead create your own set of functions and pass references to them in the settings object.

事件处理

开发人员必须定义一系列JavaScript函数来处理SWFUpload事件回调,这些函数会在不同的重要事件发生时得到调用。

通过处理SWFUpload的事件,开发人员能够提供关于上传进度、出错信息以及上传完成等的信息反馈。开发人员不应该覆盖存储在SWFUpload.prototype中的函数,相反地,应该创建你自己的一系列函数并在设置对象中将引用传递给它们。

例如: swfupload事件处理和初始化

// uploadStart 事件处理器.该函数变量在设置对象中指定给了upload_start_handler属性。

var myCustomUploadStartEventHandler = function (file) {
var continue_with_upload;

if (file.name === "the sky is blue") {
continue_with_upload = true;
} else {
continue_with_upload = false;
}

return continue_with_upload;
};

//uploadSuccess处理事件。该函数变量在设置对象中指定给了upload_success_handler属性。
var myCustomUploadSuccessEventHandler = function (file, server_data, receivedResponse) {
alert("The file " + file.name + " has been delivered to the server. The server responded with " + server_data);
};

//创建SWFUpload实例,设置事件回调函数
var swfu = new SWFUpload({
upload_url : "http://www.swfupload.org/upload.php",
flash_url : "http://www.swfupload.org/swfupload.swf",
file_size_limit : "200 MB",

upload_start_handler : myCustomUploadStartEventHandler,
upload_success_handler : myCustomUploadSuccessEventHandler
});

SWFUpload JavaScript 对象

构造函数

SWFUpload(settings object)

返回: 一个SWFUpload实例

var swfupload_instance = new SWFUpload(settings_object);

全局变量和常量

特有的全局变量和常量是与SWFUpload对象相关的,它们对SWFUpload的高级应用程序和处理错误都是很有用的,它们都是只读的.

SWFUpload.instances

SWFUpload.instances 是一个对象,其中包含了页面中加载的每个SWFUpload的实例的引用。Flash Player 依赖此对象来调用正确的事件处理器. SWFUpload.instances是通过movieName属性来进行索引的.

SWFUpload.movieCount

SWFUpload.movieCount是一个全局变量,用于追踪已经创建的SWFUpload实例个数,并帮助确认每一个Flash影片分配了一个惟一的movieName。

SWFUpload.QUEUE_ERROR

SWFUpload.QUEUE_ERROR 是一个包含了错误码的简单JS对象,一般用来判断在fileQueueError事件发出的错误码,以确定fileQueueError的具体类型.

1.QUEUE_LIMIT_EXCEEDED - 用于指示用户试图入列超过设置允许的文件数量。一旦队列中的文件被更新和删除,则允许用户入列其它的文件。

2.FILE_EXCEEDS_SIZE_LIMIT - 用于指示选择的文件大小超过了由file_size_limit设置的值

3.ZERO_BYTE_FILE - 用于指示选择的文件为空.Flash Player 不会处理空文件.窗口快捷文件也会引发这个错误.

4.INVALID_FILETYPE - 选择的文件的扩展名与file_types设置的值不相匹配。用户可以手动输入一个文件名来绕开file_types的限制。

SWFUpload.UPLOAD_ERROR

1.SWFUpload.UPLOAD_ERROR 是一个包含上传错误码常量的简单对象。它通常用来判断在uploadError事件中发出的错误码类型。

2.HTTP_ERROR - 文件上传试图执行,但服务端没有返回200状态码。

3.MISSING_UPLOAD_URL - 没有设置upload_url.

4.IO_ERROR - 读或传输文件过程中出现的某种错误.这种错误通常是由于服务端出现未料到地连接中断所引起的.

5.SECURITY_ERROR - 上传违反了安全限制。这种错误很少出现。

6.UPLOAD_LIMIT_EXCEEDED - 用户试图上传的文件数超过了file_upload_limit设置的值.

7.UPLOAD_FAILED - 上传失败。这种错误一般很少见。

8.SPECIFIED_FILE_ID_NOT_FOUND - 文件ID传递给了startUpload,但file ID无法找到。

9.FILE_VALIDATION_FAILED - 文件验证失败,uploadStart事件返回false.

10.FILE_CANCELLED - cancelUpload被调用。

11.UPLOAD_STOPPED - stopUpload被调用。

SWFUpload.FILE_STATUS

SWFUpload.FILE_STATUS 是一个包含了文件状态码常量的简单对象。它可以用来检查File对象上文件状态属性。

1.QUEUED - 指示文件正等待入列。
2.IN_PROGRESS - 指示文件当前正在上传
3.ERROR -指示文件出现了队列或上传错误
4.COMPLETE - 指示文件已经成功上传到了服务器
5.CANCELLED - 指示文件由于调用了cancelUpload而取消了上传

SWFUpload.BUTTON_ACTION

SWFUpload.BUTTON_ACTION 是一个包含了button action代码常量的简单对象。它同button_action设置一起来设置基于文件对话框按钮Flash的行为。

1.SELECT_FILE - 当Flash button被点击的时候,文件对话框只允许选择一个文件。
2.SELECT_FILES - 当Flash button被点击的时候,文件对话框允许选择多个文件。
3.START_UPLOAD - 当Flash button被点击的时候,队列中的第一个文件将被上传。

SWFUpload.CURSOR

SWFUpload.CURSOR 是一个包含了按钮光标代码常量的简单对象。它与button_cursor设置一起使用来设置当鼠标光标停留于Flash button的行为.

1.ARROW - 光标将会显示为箭头指针。
2.HAND - 光标将会显示为手形指针。

SWFUpload.WINDOW_MODE

SWFUpload.WINDOW_MODE是一个包含了该SWF插入到页面中的wmode属性的JS对象.可以通过设置button_window_mode属性来告诉浏览器具体以哪种模式显示此SWF。


WINDOW是默认的模式. 该SWF将位于页面元素的最高层级。

OPAQUE 该SWF可以被页面类的其他元素通过层级的设置来覆盖它。

TRANSPARENT 该SWF的背景是透明的,可以透过它看到背后的页面元素。

属性

下面这个列表是相关属性的具体描述。使用其它属性或者对只读属性进行了写的操作都会造成SWFUpload出现问题。

customSettings (read/write)

customSettings属性是一个空的JavaScript对象,它被用来存储跟SWFUpload实例相关联的数据。它的内容可以使用设置对象中的custom_settings属性来初始化。

Example:

// 使用自定义的配置来初始化SWFUpload对象
var swfu = new SWFUpload({
custom_settings : {
custom_setting_1 : "custom_setting_value_1",
custom_setting_2 : "custom_setting_value_2",
custom_setting_n : "custom_setting_value_n",
}
});

swfu.customSettings.custom_setting_1 = "custom_setting_value_1"; // 更改一个存在的自定义设置
swfu.customSettings.myNewCustomSetting = "new custom setting value"; // 添加一个新的自定义设置

//用一个全新的对象重写customSettings
swfu.customSettings = {
custom_setting_A : "custom_setting_value_A",
custom_setting_B : "custom_setting_value_B"
};

存储在customSettings对象中的值可以很轻松地在事件处理器中访问:

function uploadSuccess(file, serverData, receivedResponse) {
if (this.customSettings.custom_setting_A === true) {
alert("Checked the custom setting!");
}
}

movieName(只读)

包含了该SWFUpload实例的惟一影片名字。该值被传递给Flash,用来完成Flash和JavaScript的通信。该值被用来索引实例在SWFUpload.instances数组中的位置,你无法更改此值。

Methods

下面的方法用来操作SWFUpload。其中有些方法可以跟元素(例如,按钮)的点击事件绑定,其它的方法供SWFUpload内部处理事件中调用。

object addSetting(setting_name, value, default_value)

废弃. 此函数用来设置值。如果值为undefined,那么值为default_value设定的值。此函数是在SWFUpload初始化时被调用的。使用此函数来更新设置的值不会改变在Flash控制元素中设定的值。

此函数将返回存储在设置中的值。

object getSetting(setting_name)

废弃。此函数用来获取addSetting中设置的值。如果没有找到,将返回空字符串。

object retrieveSetting(setting_value, default_value)

v2.1.0已经删除此函数。此函数的功能除了不能修改内部的设置的值外,其它功能与addSetting相似。retrieveSetting返回设置的值(未定义时返回default_value)

bool destroy()

v2.1.0中新增

用于将一个SWFUpload实例从页面中销毁。不但删除DOM中的Flash元素,同时还删除SWFUpload实例的相关引用。同时它也会阻止在IE中的内存泄露。如果删除成功返回true,失败返回false。

void displayDebugInfo()

调用debug方法,在Debug输出框中显示SWFUpload实例的设置信息,如果设置中的debug属性是true,那么默认是在实例化完成以后自动调用此方法。

void selectFile()

废弃.不兼容Flash Player 10.

selectFile causes the Flash Control to display a File Selection Dialog window. A single file may be selected from the Dialog window.

Calling selectFile begins the File Event Chain.

void selectFiles()

Deprecated. Not compatible with Flash Player 10.

selectFiles causes the Flash Control to display a File Selection Dialog window. A multiple files may be selected from the Dialog window.

Calling selectFiles begins the File Event Chain.

void startUpload(file_id)

startUpload causes the file specified by the file_id parameter to start the upload process. If the file_id parameter is omitted or undefined then the first file in the queue is uploaded.

Calling startUpload begins the Upload Event Chain.

void cancelUpload(file_id, trigger_error_event)

cancelUpload cancels the file specified by the file_id parameter. The file is then removed from the queue.

If the file_id parameter is omitted or undefined then the first file in the queue is cancelled.

The trigger_error_event is optional. If set to false the uploadError event is suppressed.

void stopUpload()

stopUpload stops and re-queues the file currently being uploaded.

After the uploading file is stopped the uploadError event is fired. If no file is being uploaded then nothing happens and no event is fired.

object getStats()

Retrieves the stats object.

void setStats(stats_object)

The Stats Object may be modified. This is useful if you wish to change the number of successful uploads or upload errors after an upload has completed.

object getFile(file_id|index)

getFile is used to retrieve a File Object from the queue. The file retrieved by passing in a file id (the id property from a file object) or a file index (the index property from a file object).

When getting a file by file_id only files in the queue are available. If the file is not found null is returned.

When getting a file by index all queued (or files that generated a queue error) are available. If the index is out of range then null is returned

void addPostParam(name, value)

The addPostParam function adds a name/value pair that will be sent in the POST for all files uploaded.

The name/value pair will also appear in the post_params setting.

void removePostParam(name)

The removePostParam function removes a name/value pair from the values sent with the POST for file uploads.

The name/value pair is also be removed from the post_params setting.

bool addFileParam(file_id, name, value)

The addFileParam function adds a name/value pair that will be sent in the POST with the file specified by the file_id parameter.

The name/value pair will only be sent with the file it is added to. To send name/value pairs with all uploads use the post_param setting.

bool removeFileParam(file_id, name)

The removeFileParam function removes a name/value pair from a file upload that was added using addFileParam.

If the name/value pair was not found then 'false' is returned.

void setUploadURL(url)

Dynamically modifies the upload_url setting.

void setPostParams(param_object)

Dynamically modifies the post_params setting. Any previous values are over-written. The param_object should be a simple JavaScript object. All names and values must be strings.

void setFileTypes(types, description)

Dynamically updates the file_types and file_types_description settings. Both parameters are required.

void setFileSizeLimit(file_size_limit)

Dynamically modifies the file_size_limit setting. This applies to all future files that are queued. The file_size_limit parameter will accept a unit. Valid units are B, KB, MB, and GB. The default unit is KB.

Examples: 2147483648 B, 2097152, 2097152KB, 2048 MB, 2 GB

void setFileUploadLimit(file_upload_limit)

Dynamically modifies the file_upload_limit setting. The special value zero (0) indicates "no limit".

void setFileQueueLimit(file_queue_limit)

Dynamically modifies the file_queue_limit setting. The special value zero (0) indicates "no limit".

void setFilePostName(file_post_name)

Dynamically modifies the file_post_name setting. The Linux Flash Player ignores this setting.

void setUseQueryString(use_query_string)

Dynamically modifies the use_query_string setting. When true this forces SWFUpload to send post parameters on the query string rather than in the post. The use_query_string parameter should be a boolean true or false.

void setDebugEnabled(debug_enabled)

Dynamically enables or disables debug output. The debug_enabled parameter should be a boolean true or false.

void setButtonImageURL(url)

Dynamically change the image used in the Flash Button. The image url must be relative to the swfupload.swf file, an absolute path (e.g., starting with a /), or a fully qualified url (e.g., http://www.swfupload.org/buttonImage.png). Any image format supported by Flash can be loaded. The most notable formats are jpg, gif, and png.

The button image is expected to be a button sprite (or a single image file with several images stacked together). The image will be used to represent all the button states by moving the image up or down to only display the needed portion. These states include: normal, hover, click, disabled. See the sample button images.

void setButtonDimensions(width, height)

Dynamically change the Flash button's width and height. The values should be numeric and should not include any units. The height value should be 1/4th of the total button image height so the button state sprite images can be displayed correctly

void setButtonText(text)

Sets the text that should be displayed over the Flash button. Text that is too large and overflows the button size will be clipped.

The text can be styled using HTML supported by the Flash Player (Adobe Documentation)

void setButtonTextStyle(css_style_text)

Sets the CSS styles used to style the Flash Button Text. CSS should be formatted according to the Flash Player documentation (Adobe Documentation)

Style classes defined here can then be referenced by HTML in the button_text setting.

void setButtonTextPadding(left, top)

Sets the top and left padding of the Flash button text. The values may be negative.

void setButtonDisabled(isDisabled)

When 'true' changes the Flash Button state to disabled and ignores any clicks.

void setButtonAction(buttonAction)

Sets the action taken when the Flash button is clicked. Valid action values are taken from the BUTTON_ACTION constants.

void setButtonCursor(buttonCursor)

Sets the mouse cursor shown when hovering over the Flash button. Valid cursor values are taken from the CURSOR constants.

Events

SWFUpload fires various events during its operation. These events can be handled by the developer to update the UI, change behavior, or report errors.

All SWFUpload events are called in the context of a SWFUpload instance. This means that the 'this' object refers to the SWFUpload instance that fired the event.

SWFUpload events should be set only by assigning the event handler function in the settings object during object initialization. You should not override the internal functions belonging to the SWFUpload.prototype object.

During a file upload events are usually called in this order (the Upload Event Chain):

uploadStart
uploadProgress (called over and over again as the file uploads)
uploadError (called if some kind of error occurs, the file is canceled or stopped)
uploadSuccess (the upload finished successfully, data returned from the server is available)
uploadComplete (the upload is complete and SWFUpload is ready to start the next file)
flashReady()

flashReady is an internal event that should not be overwritten. It is called by the Flash Control to notify SWFUpload that the Flash movie has loaded and is ready to accept commands.

swfUploadLoaded()

The swfUploadLoaded event is fired by flashReady. It is settable. swfUploadLoaded is called to let you know that it is safe to call SWFUpload methods.

fileDialogStart()

fileDialogStart is fired after selectFile for selectFiles is called. This event is fired immediately before the File Selection Dialog window is displayed. However, the event may not execute until after the Dialog window is closed.

fileQueued(file object)

The fileQueued event is fired for each file that is queued after the File Selection Dialog window is closed.

fileQueueError(file object, error code, message)

The fileQueueError event is fired for each file that was not queued after the File Selection Dialog window is closed. A file may not be queued for several reasons such as, the file exceeds the file size, the file is empty or a file or queue limit has been exceeded.

The reason for the queue error is specified by the error code parameter. The error code corresponds to a SWFUpload.QUEUE_ERROR constant.

fileDialogComplete(number of files selected, number of files queued, total number of files in the queued)

The fileDialogComplete event fires after the File Selection Dialog window has been closed and all the selected files have been processed. The 'number of files queued' argument indicates the number of files that were queued from the dialog selection (as opposed to the number of files in the queue).

If you want file uploading to begin automatically this is a good place to call 'this.startUpload()'

uploadStart(file object)

uploadStart is called immediately before the file is uploaded. This event provides an opportunity to perform any last minute validation, add post params or do any other work before the file is uploaded.

The upload can be cancelled by returning 'false' from uploadStart. If you return 'true' or do not return any value then the upload proceeds. Returning 'false' will cause an uploadError event to fired.

uploadProgress(file object, bytes complete, total bytes)

The uploadProgress event is fired periodically by the Flash Control. This event is useful for providing UI updates on the page.

Note: The Linux Flash Player fires a single uploadProgress event after the entire file has been uploaded. This is a bug in the Linux Flash Player that we cannot work around.

uploadError(file object, error code, message)

The uploadError event is fired any time an upload is interrupted or does not complete successfully. The error code parameter indicates the type of error that occurred. The error code parameter specifies a constant in SWFUpload.UPLOAD_ERROR.

Stopping, Cancelling or returning 'false' from uploadStart will cause uploadError to fire. Upload error will not fire for files that are cancelled but still waiting in the queue.

uploadSuccess(file object, server data, received response)

uploadSuccess is fired when the entire upload has been transmitted and the server returns a HTTP 200 status code. Any data outputted by the server is available in the server data parameter.

Due to some bugs in the Flash Player the server response may not be acknowledged and no uploadSuccess event is fired by Flash. In this case the assume_success_timeout setting is checked to see if enough time has passed to fire uploadSuccess anyway. In this case the received response parameter will be false.

The http_success setting allows uploadSuccess to be fired for HTTP status codes other than 200. In this case no server data is available from the Flash Player.

At this point the upload is not yet complete. Another upload cannot be started from uploadSuccess.

uploadComplete(file object)

uploadComplete is always fired at the end of an upload cycle (after uploadError or uploadSuccess). At this point the upload is complete and another upload can be started.

If you want the next upload to start automatically this is a good place to call this.uploadStart(). Use caution when calling uploadStart inside the uploadComplete event if you also have code that cancels all the uploads in a queue.

debug(message)

The debug event is called by the SWFUpload library and the Flash Control when the debug setting is set to 'true'. If the debug event is not overridden then SWFUpload writes debug messages to the SWFUpload console (a text box dynamically added to the end of the page body).

SWFUpload Utility Objects

Settings object

The settings object is a JavaScript object that provides the settings for the SWFUpload instance. Each setting should only appear once. Many settings are optional and provide suitable default values if omitted. See the setting details for required and optional settings.

Example:

{
upload_url : "http://www.swfupload.org/upload.php",
flash_url : "http://www.swfupload.org/swfupload.swf",

file_post_name : "Filedata",
post_params : {
"post_param_name_1" : "post_param_value_1",
"post_param_name_2" : "post_param_value_2",
"post_param_name_n" : "post_param_value_n"
},
use_query_string : false,
requeue_on_error : false,
http_success : [201, 202],
assume_success_timeout : 0,
file_types : "*.jpg;*.gif",
file_types_description: "Web Image Files",
file_size_limit : "1024",
file_upload_limit : 10,
file_queue_limit : 2,

debug : false,

prevent_swf_caching : false,
preserve_relative_urls : false,

button_placeholder_id : "element_id",
button_image_url : "http://www.swfupload.org/button_sprite.png",
button_width : 61,
button_height : 22,
button_text : "<b>Click</b> <span class="redText">here</span>",
button_text_style : ".redText { color: #FF0000; }",
button_text_left_padding : 3,
button_text_top_padding : 2,
button_action : SWFUpload.BUTTON_ACTION.SELECT_FILES,
button_disabled : false,
button_cursor : SWFUpload.CURSOR.HAND,
button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,

swfupload_loaded_handler : swfupload_loaded_function,
file_dialog_start_handler : file_dialog_start_function,
file_queued_handler : file_queued_function,
file_queue_error_handler : file_queue_error_function,
file_dialog_complete_handler : file_dialog_complete_function,
upload_start_handler : upload_start_function,
upload_progress_handler : upload_progress_function,
upload_error_handler : upload_error_function,
upload_success_handler : upload_success_function,
upload_complete_handler : upload_complete_function,
debug_handler : debug_function,

custom_settings : {
custom_setting_1 : "custom_setting_value_1",
custom_setting_2 : "custom_setting_value_2",
custom_setting_n : "custom_setting_value_n",
}
}
Settings Description

upload_url

The upload_url setting accepts a full, absolute, or relative target URL for the uploaded file. Relative URLs should be relative to document. The upload_url should be in the same domain as the Flash Control for best compatibility.

If the preserve_relative_urls setting is false SWFUpload will convert the relative URL to an absolute URL to avoid the URL being interpreted differently by the Flash Player on different platforms. If you disable SWFUploads conversion of the URL relative URLs should be relative to the swfupload.swf file.

file_post_name

The file_post_name allows you to set the value name used to post the file. This is not related to the file name. The default value is 'Filedata'. For maximum compatibility it is recommended that the default value is used.

post_params

The post_params setting defines the name/value pairs that will be posted with each uploaded file. This setting accepts a simple JavaScript object. Multiple post name/value pairs should be defined as demonstrated in the sample settings object. Values must be either strings or numbers (as interpreted by the JavaScript typeof function).

Note: Flash Player 8 does not support sending additional post parameters. SWFUpload will automatically send the post_params as part of the query string.

use_query_string

The use_query_string setting may be true or false. This value indicates whether SWFUpload should send the post_params and file params on the query string or the post. This setting was introduced in SWFUpload v2.1.0.

preserve_relative_urls

A boolean value that indicates whether SWFUpload should attempt to convert relative URLs used by the Flash Player to absolute URLs. If set to true SWFUpload will not modify any URLs. The default value is false.

requeue_on_error

The requeue_on_error setting may be true or false. When this setting is true any files that has an uploadError (excluding fileQueue errors and the FILE_CANCELLED uploadError) is returned to the front of the queue rather than being discarded. The file can be uploaded again if needed. To remove the file from the queue the cancelUpload method must be called.

All the events associated with a failed upload are still called and so the requeuing the failed upload can conflict with the Queue Plugin (or custom code that uploads the entire queue). Code that automatically uploads the next file in the queue will upload the failed file over and over again if care is not taken to allow the failing upload to be cancelled.

This setting was introduced in SWFUpload v2.1.0.

http_success

An array that defines the HTTP Status Codes that will trigger success. 200 is always a success. Also, only the 200 status code provides the serverData.

When returning and accepting an HTTP Status Code other than 200 it is not necessary for the server to return content.

assume_success_timeout

The number of seconds SWFUpload should wait for Flash to detect the server's response after the file has finished uploading. This setting allows you to work around the Flash Player bugs where long running server side scripts causes Flash to ignore the server response or the Mac Flash Player bug that ignores server responses with no content.

Testing has shown that Flash will ignore server responses that take longer than 30 seconds after the last uploadProgress event.

A timeout of zero (0) seconds disables this feature and is the default value. SWFUpload will wait indefinitely for the Flash Player to trigger the uploadSuccess event.

file_types

The file_types setting accepts a semi-colon separated list of file extensions that are allowed to be selected by the user. Use '*.*' to allow all file types.

file_types_description

A text description that is displayed to the user in the File Browser dialog.

file_size_limit

The file_size_limit setting defines the maximum allowed size of a file to be uploaded. This setting accepts a value and unit. Valid units are B, KB, MB and GB. If the unit is omitted default is KB. A value of 0 (zero) is interpreted as unlimited.

Note: This setting only applies to the user's browser. It does not affect any settings or limits on the web server.

file_upload_limit

Defines the number of files allowed to be uploaded by SWFUpload. This setting also sets the upper bound of the file_queue_limit setting. Once the user has uploaded or queued the maximum number of files she will no longer be able to queue additional files. The value of 0 (zero) is interpreted as unlimited. Only successful uploads (uploads the trigger the uploadSuccess event) are counted toward the upload limit. The setStats function can be used to modify the number of successful uploads.

Note: This value is not tracked across pages and is reset when a page is refreshed. File quotas should be managed by the web server.

file_queue_limit

Defines the number of unprocessed files allowed to be simultaneously queued. Once a file is uploaded, errored, or cancelled a new files can be queued in its place until the queue limit has been reached. If the upload limit (or remaining uploads allowed) is less than the queue limit then the lower number is used.

flash_url

The full, absolute, or relative URL to the Flash Control swf file. This setting cannot be changed once the SWFUpload has been instantiated. Relative URLs are relative to the page URL.

flash_width

(Removed in v2.1.0) Defines the width of the HTML element that contains the flash. Some browsers do not function correctly if this setting is less than 1 px. This setting is optional and has a default value of 1px.

flash_height

(Removed in v2.1.0) Defines the height of the HTML element that contains the flash. Some browsers do not function correctly if this setting is less than 1 px. This setting is optional and has a default value of 1px.

flash_color

Removed in v2.2.0 This setting sets the background color of the HTML element that contains the flash. The default value is '#FFFFFF'.

Note: This setting may not be effective in "skinning" 1px flash element in all browsers.

prevent_swf_caching

Added in v2.2.0 This boolean setting indicates whether a random value should be added to the Flash URL in an attempt to prevent the browser from caching the SWF movie. This works around a bug in some IE-engine based browsers.

Note: The algorithm for adding the random number to the URL is dumb and cannot handle URLs that already have some parameters.

debug

A boolean value that defines whether the debug event handler should be fired.

button_placeholder_id

(Added in v2.2.0) This required setting sets the ID of DOM element that will be replaced by the Flash Button. This setting overrides the button_placeholder setting. The Flash button can be styled using the CSS class 'swfupload'.

button_placeholder

(Added in v2.2.0) This required setting sets the DOM element that will be replaced by the Flash Button. This setting is only applied if the button_placeholder_id is not set. The Flash button can be styled using the CSS class 'swfupload'.

button_image_url

(Added in v2.2.0) Fully qualified, absolute or relative URL to the image file to be used as the Flash button. Any Flash supported image file format can be used (another SWF file or gif, jpg, or png).

This URL is affected by the preserve_relative_urls setting and should follow the same rules as the upload_url setting.

The button image is treated as a sprite. There are 4 button states that must be represented by the button image. Each button state image should be stacked above the other in this order: normal, hover, down/click, disabled.

button_width

(Added in v2.2.0) A number defining the width of the Flash button.

button_height

(Added in v2.2.0) A number defining the height of the Flash button. This value should be 1/4th of the height or the button image.

button_text

(Added in v2.2.0) Plain or HTML text that is displayed over the Flash button. HTML text can be further styled using CSS classes and the button_text_style setting. See Adobe's Flash documentation for details.

button_text_style

(Added in v2.2.0) CSS style string that defines how the button_text is displayed. See Adobe's Flash documentation for details.

button_text_top_padding

(Added in v2.2.0) Used to vertically position the Flash button text. Negative values may be used.

button_text_left_padding

(Added in v2.2.0) Used to horizontally position the Flash button text. Negative values may be used.

button_action

(Added in v2.2.0) Defines the action taken when the Flash button is clicked. Valid action values can be found in the swfupload.js file under the BUTTON_ACTION object.

button_disabled

(Added in v2.2.0) A boolean value that sets whether the Flash button is in the disabled state. When in the disabled state the button will not execute any actions.

button_cursor

(Added in v2.2.0) Used to define what type of mouse cursor is displayed when hovering over the Flash button.

button_window_mode

(Added in v2.2.0) Sets the WMODE property of the Flash Movie. Valid values are available in the SWFUpload.WINDOW_MODE constants.

custom_settings

The custom_settings setting allows developers to safely attach additional information to a SWFUpload instance without worrying about affecting internal SWFUpload values or changes in new SWFUpload versions. This setting accepts a JavaScript object.

Once instantiated the custom settings are accessed in the 'customSettings' property of the SWFUpload instance.

var swfu = new SWFUpload({
custom_settings : {
"My Setting" : "This is my setting",
myothersetting : "This is my other setting",
integer_setting : 100,
a_dom_setting : document.getElementById("some_element_id")
}
});

var my_setting = swfu.customSettings["My Setting"]);
swfu.customSettings["My Setting"] = "This is my new setting";
swfu.customSetting.myothersetting = "another new value";
swfu.customSetting.integer_setting += 25;
swfu.customSetting["a_dom_setting"].style.visibility = "hidden";
Event Handlers

The remaining settings define the event handlers called by SWFUpload during its operation. JavaScript functions should be defined to handle these events as needed.

File Object

The file object is passed to several event handlers. It contains information about the file. Some operating systems do not fill in all the values (this is especially true for the createdate and modificationdate values).

{
id : string, // SWFUpload file id, used for starting or cancelling and upload
index : number, // The index of this file for use in getFile(i)
name : string, // The file name. The path is not included.
size : number, // The file size in bytes
type : string, // The file type as reported by the client operating system
creationdate : Date, // The date the file was created
modificationdate : Date, // The date the file was last modified
filestatus : number, // The file's current status. Use SWFUpload.FILE_STATUS to interpret the value.

}
Stats Object

The Stats object provides information about the upload queue.

That stats object contains the following properties:

{
in_progress : number // 1 or 0 indicating if a file upload is currently in progress
files_queued : number // The number of files currently in the queue
successful_uploads : number // The number of files that have uploaded successfully (caused uploadSuccess to be fired)
upload_errors : number // The number of files that have had errors (excluding cancelled files)
upload_cancelled : number // The number of files that have been cancelled
queue_errors : number // The number of files that caused fileQueueError to be fired
}
All these values can be updated using setStats() except the in_progress and files_queued values.

SWFUpload Plug-ins

With SWFUpload v2.0 several plugins have been introduced. They are provided to help with common tasks associated with implementing SWFUpload.

Currently most of the documentation for using the plugins is contained in the plugin JavaScript file.

SWFObject

The SWFObject plugin uses the SWFObject library to handle the embedding of the SWFUpload Flash Component into the page.

This plugin also provides support for Document Ready loading and Flash Version Detection. Usage details are documented in the plugin file itself. You should not use the SWFObject's Document Ready loading mixed with another libraries DOMReady. Use one or the other but not both.

Flash Player 10: Because Flash Player 10 requires the SWFUpload swf to act is a button the movie must be visible in order for it to load. If the button_placeholder_id is set to an element that is hidden (visibility set to hidden or display set to none) SWFUpload will fail to load.

Cookies

In response to the Flash Cookie Bug the Cookies Plugin automatically retrieves your browser's cookies and sends them with the upload. The are sent as POST or GET variables to the upload url.

Note that this plugin sends the cookies name/values in the POST or GET. On the server side they will not be accessible as cookies. Some frameworks that automatically check cookies for session or authentication values still will not be able to find the values.

Queue Handling

This plugin provides Queue Handling features such as entire queue uploading, entire queue cancelling and automatic starting of uploads after being queued.

Speed

This Plugin extends the 'file' object with several properties that describe the current upload. This includes current speed, average speed, elapsed time, remaining time and more.

Known Issues

The Flash Player and many Browsers have bugs that have a direct impact on the performance of SWFUpload. While we have worked hard to get around many issues but there are some things that we cannot fix.

Cancelling in Linux

Older Flash 9 Players for Linux cause the browser to crash if an upload is cancelled. Newer Flash 9 Players behave better.

Upload Progress in Linux

The Flash Player in Linux sends a single uploadProgress event after the file has finished uploading.

In some distributions the entire browser locks up while the upload is in progress.

Upload Progress in OS X

There have been some reports that uploadProgress events are not fired in MAC Flash Players. The specifics haven't been pinned down but be aware of the possible issue.

MIME Type

The Flash Player uploads all files with a mime type of application/octet-stream regardless of the file's actual mime type.

Maximum number of selected files

The Flash Player does not impose a maximum number of selected files. However, it builds a selected files string which does have a maximum length. The string is built using the file's name and the separator [space]. The total number of files selected is determined by the sum of the lengths of the file names and a prefixed and postfixed  character (2 characters) and the number of files selected minus one times 3 (for the separator string)

This limitation may vary from system to system. If a use selects too many files they will be receive a Flash Player generated warning message and will be left at the File Selection Dialog.

Proxies

The Flash Player may not properly use proxies. It does not handle authenticating proxies well (if at all) and will some-times crash.

Some anti-virus software uses a proxy to scan uploads and cause SWFUpload to believe the entire file has been uploaded. SWFUpload will fire uploadProgress events very quickly until it reaches 100% and will then seem to pause until the proxy completes uploading the file to the server.

Apache mod_security

Apache's mod_security validates POST to the server. Flash Player has implemented an edge case (there is argument as to whether it is invalid or note) POST for file uploads and so servers implementing mod_security will reject the upload. mod_security can be disabled using your .htaccess file

SSL

There have been some reports that the Flash Player cannot upload through SSL. The issue has not been pinned down but uploading over SSL may be unreliable. There especially seems to be an issue with using self-signed certificates.

Also, SSL tickets from untrusted Certificate Authorities (CA) do not work as Flash does not provide a method for accepting the certificate. It has been noted that, like the cookie bug, that Flash Player on Windows obtains its trusted CA list from Internet Explorer regardless of the browser in use.

Authentication

HTTP Authentication is not well supported by the Flash Player. Later versions of Flash Player behave better. Old version of Flash Player would crash the browser.

Prematurely terminated connections

Prematurely ending the response (such as a Response.end() in ASP.Net) can sometimes cause successful uploads to be reported as failed.

Filedata in Linux

Changing the Filedata value (file_post_name setting) is ignored in Linux Flash Players.

Cookie issue

On Windows the Non-IE Flash Player plugin (FireFox, Opera, Safari, etc) will send the IE cookies regardless of the browser used. This breaks authentication and sessions for many server-side scripting technologies.

Developers should manually pass Session and Authentication cookie information and manually restore Sessions on the Server Side if they wish to use Sessions

The SWFUpload package contains work-around sample code for PHP and ASP.Net

ExternalInterface bugs

Flash Player does not properly escape data when communication with the browser/JavaScript. SWFUpload goes to great lengths to work-around this issue. If this bug is fixed in future Flash Players/Browsers then SWFUpload will send extra escaped data.

Server Data length bugs

Very long server data is corrupted on Mac and Linux Flash Players. Server data will be truncated, garbled, and/or repeated. We recommend keeping data returned from the server short and concise.

Avant Browser

For some users the Avant Browser does not work with SWFUpload after the Flash Control has been cached. This has been reproduced by the SWFUpload developers but the Avant Browser developers did not experience any problems.

When the page is reloaded SWFUpload loads and fires the swfupload_loaded event. However, none of the ExternalInterface callback functions are defined on the movie element. SWFUpload v2.0.2 has added checks which prevent swfupload_loaded from firing if the callback functions are not detected.

SWFUpload v2.2.0 added the prevent_swf_caching setting that attempts to work around this issue.

File Dialog & Page Changing

Leaving or reloading the current page while the File Browser Dialog window is open will cause the browser to crash (all browsers, all OSs). Most commonly this is caused by failing to cancel a click event on an <a> tag where the onclick event calls the selectFile or selectFiles function.

Long Running Upload Scripts

After Flash has uploaded the file to the webserver the upload script is executed. This script handles the file whether that means saving it, creating a thumbnail, scanning for viruses, etc. If the upload script does not return any data within 30 seconds Flash will disconnect and return an IO Error. You can prevent this by returning characters or data while the script runs (if possible). For PHP, the script continues to run and complete successfully even though Flash has terminated the connection. Any data returned by the script after Flash has disconnected is lost.

WMODE / BUTTON_WINDOW_MODE

In some browsers the selected WMODE (which is set using the BUTTON_WINDOW_MODE) can prevent the Flash Control from loading if the control is not on screen. The control will finally load once the user scrolls the page so the control becomes visible.

This behavior can adversely affect the SWFObject plugin. No SWFUpload events will be fire and the button image will not be loaded until the control becomes visible.

Memory Leaks

Some browsers (especially IE) cannot recover memory used by the Flash Player when JavaScript communication via the ExternalInterface classes is used (like in SWFUpload). Creating many SWFUpload instances and/or reloading the page several times will cause the browser to consume more and more memory until it crashes or otherwise harms the system.

In v2.2.0 SWFUpload we gave implemented some preventative measures. Some of these measures are pro-active but it is still recommended that you call the destroy method when the page unloads. If you are using hundreds of SWFUpload instances on a page you should use caution and test carefully for memory leaks.

Other Mac Issues

Users have reported that uploading to subdomains does not work with the Mac Flash Player.
Users have reported that pages that redirect (HTTP Status 302) are not handled by the Mac Flash Player. Windows clients seem to handle this issue.
The flash documentation states that on OS early than OS X 10.3 the bytes loaded is always reported as -1. SWFUpload converts this to 0 but the total bytes will never be sent and 100% won't be reached. The UI should be updated to display 100% complete in uploadSuccess or uploadComplete events to maintain a consistent UI.
Some users have reported issues if there is a space character in the upload_url for the Mac Flash Player. Avoid spaces or try replacing them with + or %20.
Users have reported that the Flash Player for Mac adds the PORT to the HTTP_HOST server variable (e.g., http://www.example.com:80). If you are checking this variable in your server-side script be aware of the possible issue.
分享到:
评论

相关推荐

    新能源车联网项目案例.zip

    1、该资源内项目代码经过严格调试,下载即用确保可以运行! 2、该资源适合计算机相关专业(如计科、人工智能、大数据、数学、电子信息等)正在做课程设计、期末大作业和毕设项目的学生、或者相关技术学习者作为学习资料参考使用。 3、该资源包括全部源码,需要具备一定基础才能看懂并调试代码。 新能源车联网项目案例.zip新能源车联网项目案例.zip新能源车联网项目案例.zip 新能源车联网项目案例.zip新能源车联网项目案例.zip新能源车联网项目案例.zip 新能源车联网项目案例.zip新能源车联网项目案例.zip新能源车联网项目案例.zip 新能源车联网项目案例.zip新能源车联网项目案例.zip新能源车联网项目案例.zip 新能源车联网项目案例.zip新能源车联网项目案例.zip新能源车联网项目案例.zip 新能源车联网项目案例.zip新能源车联网项目案例.zip新能源车联网项目案例.zip 新能源车联网项目案例.zip新能源车联网项目案例.zip新能源车联网项目案例.zip

    工业自动化领域中维伦通触摸屏与三菱PLC在码垛机程序中的协同应用

    内容概要:本文详细介绍了码垛机程序的设计与实现,重点探讨了维伦通触摸屏与三菱PLC之间的协同工作。文中首先介绍了硬件基础,即维伦通触摸屏作为人机交互界面,三菱PLC作为控制系统的大脑。接着,通过具体的梯形图和代码示例,解释了三菱PLC如何通过逻辑运算控制码垛机的各项动作,如抓取、移动和堆叠。同时,文章还讲解了触摸屏与PLC的数据通信方法,以及如何通过触摸屏设置码垛参数并传递给PLC。此外,文章深入讨论了伺服轴控制、气缸动作时序、异常处理模块、模块化设计等方面的技术细节,并提供了许多调试和优化的实际经验。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是对PLC编程和人机界面设计有一定基础的人群。 使用场景及目标:适用于需要深入了解码垛机自动化控制原理及其编程实现的专业人士。主要目标是帮助读者掌握维伦通触摸屏与三菱PLC的协同编程技巧,提高码垛机的控制精度和工作效率。 其他说明:文章不仅提供了理论知识,还包括了许多实际案例和调试技巧,有助于读者更好地理解和应用相关技术。

    51单片机PID闭环转速测量调节控制器:C语言源码与仿真实践

    内容概要:本文详细介绍了基于51单片机的PID闭环转速测量调节控制器的设计与实现。首先简述了PID控制原理,即通过比例、积分、微分三个环节来调整系统输出,确保转速稳定。接着阐述了硬件连接方式,包括光电编码器用于转速测量和PWM信号控制电机转速的方法。文中提供了完整的C语言源码,涵盖定时器中断、外部中断、PID算法实现以及PWM输出控制等方面。此外,还讨论了仿真验证过程,利用Proteus软件搭建电路并测试PID控制效果。最后,针对常见问题如积分饱和、硬件故障等提出了优化建议。 适合人群:对嵌入式系统和控制系统感兴趣的电子工程师、单片机爱好者及高校相关专业学生。 使用场景及目标:适用于学习51单片机编程、掌握PID控制算法及其应用、进行电机转速控制实验等场景。目标是帮助读者理解PID控制原理,学会编写相应的C语言代码,并能够独立完成类似项目的开发。 其他说明:文中提供的代码片段可以直接应用于实际项目中,同时附带了一些调试技巧和注意事项,有助于提高开发效率和成功率。

    光伏发电MPPT中基于粒子群算法(S函数实现)的多峰值寻优解决方案

    内容概要:本文详细介绍了如何使用粒子群算法(Particle Swarm Optimization, PSO)解决光伏发电系统中因阴影遮蔽造成的多峰值最大功率点跟踪(MPPT)问题。首先解释了阴影遮蔽对光伏系统性能的影响以及传统MPPT算法在此情况下存在的局限性。接着阐述了粒子群算法的基本原理及其优势,特别是在处理非线性和多模态优化问题方面的表现。然后展示了如何在Matlab/Simulink环境下利用S函数编写PSO算法的具体步骤,包括初始化参数设定、粒子位置与速度更新规则、适应度评估等环节。最后通过实验数据验证了所提方法的有效性,证明相比传统算法,PSO能够在更短时间内找到全局最优解,显著提高了光伏系统的发电效率。 适用人群:从事新能源研究特别是光伏领域的科研工作者和技术人员,以及对智能优化算法感兴趣的学者。 使用场景及目标:适用于需要改进现有MPPT算法以应对复杂光照条件的应用场合,旨在提高光伏系统的能量转换效率,确保在各种环境因素影响下仍能稳定运行于最大功率点附近。 其他说明:文中提供的代码片段仅为示例,实际应用时需根据具体情况进行适当调整。此外,对于初学者来说,建议先掌握基本概念后再尝试动手实践。

    《从DeepSeek到品牌跃迁(AI之于品牌的机遇与挑战)》

    《从DeepSeek到品牌跃迁(AI之于品牌的机遇与挑战)》

    等离子体模拟中氩灯放电过程的COMSOL与Python实现及其可视化

    内容概要:本文详细介绍了使用COMSOL和Python进行氩灯等离子体放电过程的模拟。首先,作者展示了基础模型参数配置,包括粒子密度、电子温度、离子迁移率等,并解释了这些参数的选择依据。接着,通过MATLAB和Python代码实现了电场计算、电流密度计算以及等离子体雪崩效应的模拟。文中还强调了时间步长控制的重要性,特别是自适应时间步长算法的应用。此外,作者利用Matplotlib和OpenGL进行了动态可视化,生动展现了放电过程中电子密度云图的演变和等离子体辉光的效果。最后,作者分享了一些实用的经验和技巧,如避免数值发散、优化计算效率等。 适合人群:对等离子体物理、数值模拟感兴趣的科研人员和技术爱好者。 使用场景及目标:适用于研究等离子体放电机制、优化模拟算法、提高计算效率以及创建逼真的等离子体可视化效果。目标是帮助读者深入理解氩灯放电的物理过程,并掌握相关模拟技术和工具。 其他说明:文章不仅提供了详细的代码实现,还分享了许多实践经验,如参数选择、数值稳定性和性能优化等方面的心得。这对于从事类似研究的人来说非常有价值。

    自动驾驶技术中AES自动紧急转向系统的控制算法与应用

    内容概要:本文详细介绍了AES(自动紧急转向)系统的工作原理及其背后的多种控制算法模型。首先探讨了基于动态TTC(碰撞时间)阈值的安全距离模型,用于决定何时进行转向。接着讨论了五次多项式路径规划算法,确保车辆在短时间内生成平滑的避障轨迹。此外,还比较了传统的纯跟踪算法和现代的MPC(模型预测控制)算法在不同速度下的表现,并解释了它们各自的优缺点。最后,文章提到在联合仿真过程中遇到的一些挑战,如轮胎动力学修正和版本兼容性问题,以及如何通过调整参数来提升系统性能。 适合人群:对自动驾驶技术和车辆控制系统感兴趣的工程师和技术爱好者。 使用场景及目标:适用于研究和开发自动驾驶车辆的团队,旨在帮助他们理解和改进自动紧急转向系统的设计和实施。 其他说明:文中提供了大量MATLAB、C/C++和Python代码片段,展示了具体的技术细节和实现方法。同时强调了实际测试中的经验和教训,对于从事相关领域的研究人员具有很高的参考价值。

    用OpenGL开发的机械臂运动仿真程序,并且实现机械手臂向四个方向的旋转.rar

    OpenGL是一种强大的图形库,用于创建2D和3D图形,广泛应用于游戏开发、科学可视化、工程设计等领域。在这个项目中,我们看到一个基于OpenGL的机械臂运动仿真程序,它能够实现机械臂在四个方向上的旋转。这样的模拟对于理解机械臂的工作原理、机器人控制算法以及进行虚拟环境中的机械臂运动测试具有重要意义。 我们需要了解OpenGL的基础知识。OpenGL是一个跨语言、跨平台的编程接口,用于渲染2D和3D矢量图形。它提供了大量的函数来处理图形的绘制,包括几何形状的定义、颜色设置、光照处理、纹理映射等。开发者通过OpenGL库调用这些函数,构建出复杂的图形场景。 在这个机械臂仿真程序中,C#被用来作为编程语言。C#通常与Windows平台上的.NET Framework配合使用,提供了一种面向对象的、类型安全的语言,支持现代编程特性如LINQ、异步编程等。结合OpenGL,C#可以构建高性能的图形应用。 机械臂的运动仿真涉及到几个关键的计算和控制概念: 1. **关节角度**:机械臂的每个部分(或关节)都有一个或多个自由度,表示为关节角度。这些角度决定了机械臂各部分的位置和方向。 2. **正向运动学**:根据关节角度计算机械臂末端执行器(如抓手)在空间中的位置和方向。这涉及将各个关节的角度转换为欧拉角或四元数,然后转化为笛卡尔坐标系的X、Y、Z位置和旋转。 3. **反向运动学**:给定末端执行器的目标位置和方向,计算出各关节所需的理想角度。这是一个逆向问题,通常需要解决非线性方程组。 4. **运动规划**:确定从当前状态到目标状态的路径,确保机械臂在运动过程中避免碰撞和其他约束。 5. **OpenGL的使用**:在OpenGL中,我们首先创建几何模型来表示机械臂的各个部分。然后,使用矩阵变换(如旋转、平移和缩放)来更新关节角度对模型的影响。这些变换组合起来,形成机械臂的动态运动。 6. **四向旋转**:机械臂可能有四个独立的旋转轴,允许它在X、Y、Z三个轴上旋转,以及额外的绕自身轴线的旋转。每个轴的旋转都由对应的关节角度控制。 7. **交互控制**:用户可能可以通过输入设备(如鼠标或键盘)调整关节角度,实时观察机械臂的运动。这需要将用户输入转换为关节角度,并应用到运动学模型中。 8. **图形渲染**:OpenGL提供了多种渲染技术,如深度测试、光照模型、纹理映射等,可以用于提高机械臂模拟的真实感。例如,可以添加材质和纹理来模拟金属表面,或者使用光照来增强立体感。 这个项目结合了OpenGL的图形渲染能力与C#的编程灵活性,构建了一个可以直观展示机械臂运动的仿真环境。通过理解并实现这些关键概念,开发者不仅能够学习到图形编程技巧,还能深入理解机器人学的基本原理。

    深圳道路交通数据集,可以用于机器学习的项目的开发,数据来源于深圳市政府开放平台,都是深圳市各个区的道路信息

    在当今社会,随着城市交通管理需求的日益增长,数据驱动的决策机制变得越来越重要。深圳作为中国的一线城市,拥有庞大的交通网络和复杂多变的交通状况,因此,构建精确的交通管理系统显得尤为迫切。为此,深圳市政府开放平台提供了宝贵的道路信息数据,形成了可供机器学习项目开发使用的“深圳道路交通数据集”。 该数据集包含了深圳市内各个区域的详细道路信息,涵盖了交通流量、车速、事故记录、天气条件等多种类型的数据,能够为研究者和开发者提供丰富的学习和实验资源。通过对这些数据的深入分析,可以发现交通流量的规律、预测交通拥堵、制定更为有效的交通管理策略。 数据集中的“traffic.sql”文件,很可能是一个结构化查询语言(SQL)文件,用于存储和管理道路交通数据集的数据库。它可能包含了创建表格、索引、视图以及存储过程等SQL命令,以便用户能够更加方便地对数据进行查询和管理。这类文件是数据库维护和操作的基础,对于数据科学家和工程师来说,掌握其内容能够更高效地进行数据的导入、导出、清洗和分析。 而“获取来源.txt”文件则可能提供了关于数据集来源和数据获取方式的详细描述。它可能包含了数据采集的时间、地点、方式以及数据的更新频率等信息。这些背景信息对于确保数据分析的可靠性和有效性至关重要,因为它们能够帮助用户理解数据的局限性和适用范围,从而使分析结果更加准确和有针对性。 除了上述两个文件之外,数据集可能还包含了其他多种格式的文件,比如CSV、JSON或Excel表格等,以便用户根据不同的使用场景和需求选择合适的数据格式。无论是在交通流量预测、事故分析、路线规划还是在智能交通系统开发等方向,这个数据集都能提供重要的支持。 深圳道路交通数据集的开放,不仅体现了政府信息化、透明化的努力,也为研究者和开发者提供了宝贵的实践平台。它将有助于推动交通管理技术的创新和发展,对缓解城市交通压力、提高道路使用效率以及保障交通安全都将起到积极的作用。随着人工智能和机器学习技术的不断进步,此类数据集的应用前景将十分广阔。

    100kW光伏并网发电系统MATLAB仿真:增量电导+积分调节器MPPT与VSC并网控制

    内容概要:本文详细介绍了100kW光伏并网发电系统的MATLAB仿真模型,重点探讨了‘增量电导+积分调节器’技术的MPPT控制器和VSC并网控制技术。MPPT控制器通过增量电导法和积分调节器相结合的方式,能够精准跟踪光伏电池的最大功率点,确保系统高效运行。VSC并网控制则实现了直流电到交流电的转换,并通过复杂的电流控制确保并网电流的质量。文中还提供了详细的MATLAB代码片段,展示了各个关键技术的具体实现。 适用人群:适用于具有一定MATLAB编程基础和技术背景的研究人员、工程师以及对光伏并网发电系统感兴趣的学者。 使用场景及目标:①帮助研究人员理解和实现光伏并网发电系统的MPPT控制和VSC并网控制;②提供详细的MATLAB代码示例,便于学习和调试;③探索光伏并网系统的优化方向,提高系统的稳定性和效率。 其他说明:文章不仅解释了理论原理,还分享了许多实用的调试技巧和注意事项,如仿真步长选择、参数设置等,有助于读者更好地掌握相关技术。

    基于Matlab/Simulink的非隔离双向DC/DC变换器双闭环控制仿真及其应用

    内容概要:本文详细介绍了如何利用Matlab/Simulink构建非隔离双向DC/DC变换器(Buck-Boost)的仿真模型,重点探讨了电压外环电流内环双闭环控制策略的设计与实现。文中不仅涵盖了主电路参数的选择、PWM信号生成、模式切换逻辑等硬件细节,还深入讨论了PI参数整定方法以及仿真过程中常见的陷阱和优化技巧。通过具体的实验数据展示了该系统的快速响应特性和稳定性,特别是在充放电模式切换时的表现。 适合人群:电力电子工程师、科研工作者、高校师生等对双向DC/DC变换器感兴趣的专业人士。 使用场景及目标:适用于研究和开发高效稳定的双向DC/DC变换器,特别是应用于新能源储能系统中,旨在提高系统的转换效率和可靠性。 其他说明:文中提供了大量实用的技术细节和实践经验分享,对于理解和掌握双向DC/DC变换器的工作原理及控制策略非常有帮助。同时提醒读者注意一些容易忽视的问题,如死区时间和电感饱和等,确保仿真结果更加贴近实际情况。

    语音去噪技术:基于GUI界面的小波、VMD与维纳滤波Python实现

    内容概要:本文详细介绍了如何利用Python构建一个图形用户界面(GUI)程序,用于实现语音去噪。该程序主要采用三种核心技术:小波变换、变分模态分解(VMD)以及维纳滤波。首先,通过tkinter库搭建了一个简洁易用的GUI界面,允许用户选择纯净语音文件和噪声文件并将其混合。接着,在信号处理阶段,依次运用小波变换进行初步去噪,VMD分解将信号分为多个模态,最后使用维纳滤波对各模态进行精细调整。文中不仅提供了详细的代码示例,还讨论了一些常见的实现技巧和注意事项,如参数设置、信号长度匹配、信噪比计算等。 适合人群:对语音处理感兴趣的开发者和技术爱好者,尤其是有一定Python编程基础的人士。 使用场景及目标:适用于希望深入了解语音去噪原理及其具体实现的研究人员或工程师。通过该项目,读者能够掌握如何结合多种算法提高语音质量,同时学会如何使用Python的相关库来构建实用的应用程序。 其他说明:作者强调了实践中的一些重要细节,例如参数的选择对于最终效果的影响,以及如何处理不同类型的声音文件。此外,还提到了一些潜在的问题解决方案,如避免因数据格式不当导致的异常情况。

    【嵌入式系统】AUTOSAR-OS与OSEK-OS的关系及其扩展分类和基本对象:汽车电子控制系统设计指南

    内容概要:本文深入探讨了AUTOSAR OS的发展及其与OSEK OS的关系,强调了AUTOSAR OS在汽车电子控制单元(ECU)中的应用。文章首先回顾了OSEK OS的基本特性,包括基于事件触发的操作机制、实时中断处理以及错误处理服务等,指出AUTOSAR OS在其基础上进行了扩展。接着介绍了AUTOSAR OS的四个扩展分类(SC1至SC4),并解释了如何根据项目需求和硬件资源选择合适的OS扩展类型。最后,详细描述了AUTOSAR OS的五大基本对象(Counter、Alarm、Schedule Table、Tasks、ISRs),阐述了它们的作用及相互关系,如Counter为Alarm和Schedule Table提供时间基准,Tasks作为OS调度的基本单元,ISRs处理中断等。; 适合人群:从事汽车电子开发的技术人员,尤其是对AUTOSAR OS有一定了解或有兴趣深入了解其架构和功能的专业人士。; 使用场景及目标:①理解AUTOSAR OS相较于OSEK OS的改进之处;②掌握不同扩展级别的特点,以便为具体的ECU产品选择最合适的OS版本;③熟悉五大基本对象的功能和应用场景,提高在AUTOSAR架构下的系统设计能力。; 其他说明:由于AUTOSAR OS与OSEK OS紧密相关,建议读者先了解ISO 17356-3标准,这有助于更好地理解AUTOSAR OS的特性和优势。此外,在实际应用中,选择OS扩展类型时应综合考虑功能安全、信息安全需求以及芯片硬件资源。

    农产品自主供销系统 2025免费JAVA微信小程序毕设

    2025免费微信小程序毕业设计成品,包括源码+数据库+往届论文资料,附带启动教程和安装包。 启动教程:https://www.bilibili.com/video/BV1BfB2YYEnS 讲解视频:https://www.bilibili.com/video/BV1BVKMeZEYr 技术栈:Uniapp+Vue.js+SpringBoot+MySQL。 开发工具:Idea+VSCode+微信开发者工具。

    直角坐标机器人MATLAB逆向运动学仿真与Simscape建模详解

    内容概要:本文详细介绍了如何使用MATLAB及其工具箱Simulink和Simscape进行直角坐标机器人的逆向运动学仿真。首先,通过导入Scape模型并正确设置坐标系,确保模型的准确性。接着,利用fsolve函数求解姿态误差函数,实现末端执行器到达指定坐标的目标。文中还强调了在搭建Simscape模型时应注意的细节,如选择正确的关节模块、设置合理的物理参数以及优化求解器配置。此外,提供了多个实用技巧,包括添加路径约束、处理摩擦系数、优化仿真速度等。最后,通过实例展示了如何验证逆向运动学的效果,并给出了常见的调试方法。 适合人群:具有一定MATLAB基础并对机器人运动控制感兴趣的工程师和技术爱好者。 使用场景及目标:适用于希望深入了解直角坐标机器人逆向运动学原理的研究人员,以及希望通过仿真手段优化机器人控制系统的设计人员。目标是掌握如何使用MATLAB和Simscape进行高效的机器人运动仿真。 其他说明:文章不仅提供了详细的代码示例,还分享了许多实践经验,帮助读者更好地理解和应用相关技术。

    MATLAB语音信号处理与去噪:基于低通巴特沃斯滤波器的设计与实现

    内容概要:本文详细介绍了利用MATLAB进行语音信号处理和去噪的方法,重点在于使用低通巴特沃斯滤波器去除音频中的特定频率噪声。首先,通过audioread函数读取音频文件并展示其时域和频域图像。然后,作者手动实现了离散傅里叶变换(DFT)函数,并将其应用于频谱分析。接着,文中展示了如何加入人为噪声(如800Hz的正弦噪声)并对含有噪声的信号进行处理。为了去除这些噪声,设计了一个6阶低通巴特沃斯滤波器,设置合适的截止频率以保留人声的同时抑制高频噪声。对于高斯白噪声,则讨论了低通滤波器的效果及其局限性。最后,验证了自定义DFT函数的准确性。 适合人群:具有一定MATLAB基础和技术背景的研究人员、学生或工程师。 使用场景及目标:适用于希望深入了解语音信号处理技术的人士,特别是那些想要掌握如何使用MATLAB实现简单有效的数字滤波器来改善音频质量的学习者。 其他说明:本文不仅提供了具体的代码示例,还解释了每个步骤背后的理论依据,帮助读者更好地理解和应用相关概念。此外,它强调了实际操作过程中可能会遇到的问题及解决方案,如相位延迟的影响等。

    基于Voronoi图的电动汽车主动配电网中电力系统规划的MATLAB围捕算法复现

    内容概要:本文详细介绍了基于Voronoi图的最小化围捕算法在电动汽车、主动配电网及电力系统规划中的MATLAB复现。首先解释了Voronoi图的基本概念及其在围捕算法中的应用,接着展示了具体的MATLAB代码实现,包括初始化参数、随机生成位置、计算Voronoi图、围捕算法的具体实现步骤。文中还探讨了该算法在电动汽车充电路径规划、分布式电源与负荷匹配方面的潜在应用价值。通过动态生成Voronoi图来分割追捕区域,使每个追捕者负责自己区域内的逃逸者,提高了资源分配和调度的效率。 适合人群:对电力系统规划、电动汽车技术和MATLAB编程感兴趣的科研人员和技术开发者。 使用场景及目标:适用于需要优化资源分配和提高系统稳定性的情景,如电动汽车充电网络规划、智能电网管理等。目标是通过算法优化,提高充电效率和电力分配合理性,保障系统的稳定运行。 其他说明:文中提供了详细的代码片段和实现思路,有助于读者理解和复现实验。同时,讨论了一些优化技巧,如动态更新Voronoi图、调整速度因子等,使得算法更加高效实用。

    【通信技术竞赛】大唐杯全国大学生通信技术大赛:5G与物联网等领域竞赛内容及备赛指南

    内容概要:大唐杯是由中国通信学会主办的全国性大学生通信技术大赛,主要面向高校本科生和研究生,旨在推动通信领域的技术创新和人才培养。比赛涵盖5G技术、物联网与边缘计算、人工智能与大数据在通信中的应用以及通信网络部署与优化等内容,分为省赛(理论+实践)和全国总决赛(复杂实操与答辩)。该比赛在通信、电子信息类专业认可度高,对保研和就业有帮助。备赛建议包括学习5G基础知识、熟悉仿真工具和实践操作训练,并参考往届真题和官方资料。比赛报名时间通常为每年1-3月,省赛在4月进行,全国总决赛在6-7月举行。; 适合人群:全国高校本科生、研究生,尤其是通信、电子信息、计算机、电子、物联网等相关专业的学生。; 使用场景及目标:①为有志于从事通信、信息技术领域工作的学生提供实战机会;②提升学生在5G、物联网、人工智能等前沿技术方面的能力;③帮助学生获得保研加分和更好的就业机会。; 其他说明:非通信专业的学生也可以参加,但需自学部分通信知识。比赛强调理论与实践相结合,建议团队成员合理分工,分别负责理论、仿真编程和实操。对于没有实验设备的学生,可以通过仿真软件和开源项目进行练习。

    Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip

    1、该资源内项目代码经过严格调试,下载即用确保可以运行! 2、该资源适合计算机相关专业(如计科、人工智能、大数据、数学、电子信息等)正在做课程设计、期末大作业和毕设项目的学生、或者相关技术学习者作为学习资料参考使用。 3、该资源包括全部源码,需要具备一定基础才能看懂并调试代码。 Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip Android实现的雷达图(Radar Chart),可用于实现对比展示,可旋转.zip

    基于GADF-CNN-BKA-LSSVM的齿轮箱故障诊断系统:从时序信号到图像处理的技术创新

    内容概要:本文介绍了一种创新的齿轮箱故障诊断系统,该系统将时序信号转化为图像并通过深度学习与优化算法进行故障检测。首先利用GADF(格拉姆角场差)将一维振动信号转换为二维图像,接着使用轻量级CNN提取图像特征,最后通过BKA优化的LSSVM进行分类。文中详细介绍了每个步骤的具体实现方法和技术细节,如GADF的Python实现、CNN的设计以及BKA优化算法的应用。此外,还讨论了IVY和POA两种附加优化算法及其应用场景。 适合人群:从事机械故障诊断、工业物联网、智能制造领域的研究人员和工程师,尤其是对深度学习和优化算法有一定了解的专业人士。 使用场景及目标:适用于工业环境中齿轮箱的实时故障监测和预测维护。主要目标是提高故障诊断的准确性,降低误报率,从而减少停机时间和维修成本。 其他说明:该系统在东南某风场的实际测试中取得了98.7%的准确率,显著优于传统方法。建议在实际应用中考虑推理速度和模型复杂度之间的平衡,并根据具体情况选择合适的优化算法。

Global site tag (gtag.js) - Google Analytics