1、关于图片上传控件,flash控件的显示效果要好一些,本人使用swfupload
2、swfupload上传控件使用方式详见文档 http://www.leeon.me/upload/other/swfupload.html
3、参照文档说明和官方demo,写一个小例子是没有任何问题的,在firefox或者chrome下如碰到302错误,错误堆栈如下
---SWFUpload Instance Info---
Version: 2.2.0 2009-03-25
Movie Name: SWFUpload_0
Settings:
upload_url: /iwebshop/index.php?controller=shop&action=goods_imgupload&photo_name=photo_name&showlist=show_list&single=false
flash_url: /iwebshopiews/default/javascript/swfupload.swf?preventswfcaching=1348582530733
use_query_string: false
requeue_on_error: false
http_success:
assume_success_timeout: 0
file_post_name: Filedata
post_params: [object Object]
file_types: *.jpg;*.jpge;*.png;*.gif
file_types_description: JPG Images
file_size_limit: 2 MB
file_upload_limit: 5
file_queue_limit: 0
debug: true
prevent_swf_caching: true
button_placeholder_id: upload
button_placeholder: Not Set
button_image_url: /iwebshop/
button_width: 50
button_height: 21
button_text: 浏览...
button_text_style: color: #000000; font-size: 16pt;
button_text_top_padding: 0
button_text_left_padding: 0
button_action: -110
button_disabled: false
custom_settings: [object Object]
Event Handlers:
swfupload_loaded_handler assigned: false
file_dialog_start_handler assigned: false
file_queued_handler assigned: false
file_queue_error_handler assigned: true
upload_start_handler assigned: false
upload_progress_handler assigned: true
upload_error_handler assigned: true
upload_success_handler assigned: true
upload_complete_handler assigned: true
debug_handler assigned: true
SWF DEBUG: SWFUpload Init Complete
SWF DEBUG:
SWF DEBUG: ----- SWF DEBUG OUTPUT ----
SWF DEBUG: Version: 2.5.0 2010-03-05 Beta 3.2
SWF DEBUG: movieName: SWFUpload_0
SWF DEBUG: Upload URL: /iwebshop/index.php?controller=shop&action=goods_imgupload&photo_name=photo_name&showlist=show_list&single=false
SWF DEBUG: File Types String: *.jpg;*.jpge;*.png;*.gif
SWF DEBUG: Parsed File Types: jpg,jpge,png,gif
SWF DEBUG: HTTP Success: 0
SWF DEBUG: File Types Description: JPG Images (*.jpg;*.jpge;*.png;*.gif)
SWF DEBUG: File Size Limit: 2097152 bytes
SWF DEBUG: File Upload Limit: 5
SWF DEBUG: File Queue Limit: 5
SWF DEBUG: Post Params:
SWF DEBUG: PHPSESSID=feec128121ce54aa04f6b4a249bd5bc9
SWF DEBUG: ----- END SWF DEBUG OUTPUT ----
SWF DEBUG:
SWF DEBUG: Stage Resize:50 by 21
SWF DEBUG: Event: fileDialogStart : Browsing files. Multi Select. Allowed file types: *.jpg;*.jpge;*.png;*.gif
SWF DEBUG: Select Handler: Received the files selected from the dialog. Processing the file list...
SWF DEBUG: Event: fileQueued : File ID: SWFUpload_0_0
SWF DEBUG: Event: fileDialogComplete : Finished processing selected files. Files selected: 1. Files Queued: 1
SWF DEBUG: StartUpload: First file in queue
SWF DEBUG: Event: uploadStart : File ID: SWFUpload_0_0
SWF DEBUG: StartUpload(): Upload Type: Normal.
SWF DEBUG: Global Post Item: PHPSESSID=feec128121ce54aa04f6b4a249bd5bc9
SWF DEBUG: ReturnUploadStart(): File accepted by startUpload event and readied for standard upload. Starting upload to /iwebshop/index.php?controller=shop&action=goods_imgupload&photo_name=photo_name&showlist=show_list&single=false for File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress (OPEN): File ID: SWFUpload_0_0 Bytes: 0. Total: 98168
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 65536. Total: 98168
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 98168. Total: 98168
SWF DEBUG: Event: uploadError: HTTP ERROR : File ID: SWFUpload_0_0. HTTP Status: 302.
EXCEPTION:
SWF DEBUG: Event: uploadComplete : Upload cycle complete.
看到红色文字302部分是不是很熟悉?我简单说明下为什么会出现这个问题
a 、flash上传图片时,会另起一个线程上传,这个线程中没有cookie,session等会话信息,包括自定义的全局变量,调用上传的url路径后台进行处理时,如果后台进行了权限或者登陆校验就会校验失败,后台校验失败就会重定向登录页面,flash这边就会报出302错误,但是上传界面不会发生跳转。
b、如果程序使用了系统框架,一般框架会有过滤器进行权限校验或者session校验,对于框架不熟悉的人可能不知道为什么发生302错误,也不知道在哪处理过滤,导致无法解决问题,这个需要仔细研究框架了。
c、对于swfupload的demo可以直接部署运行,而不报错,就是因为接收图片界面没有校验session或者权限