默认使用swfupload来上传文件到本地是可以显示进度条的,但换成了又拍云后,发现进度条一开始就100%,然后等待很长时间才有结果,进度条显示完全没有意义了。 又拍云提供的PHP SDK没有给出显示进度条的例子,通过询问又拍云客服,客服给了一个使用又拍云原生API显示进度条的例子,通过调用又拍云原生API就可以显示进度。 更多可参考又拍云的API文档:http://docs.upyun.com/api/form_api/
1.获取API KEY
登录又拍云后,在后台——>服务——>功能配置—>高级功能——>表单 API处可以打开并查看你的key
2.计算policy和signature
$options['bucket'] = '服务名'; $form_api_secret = '你的API KEY'; $upload_folder = "/test/"; //你要上传的文件夹 $options['expiration'] = time()+600; $policy = base64_encode(json_encode($options)); $signature = md5($policy.'&'.$form_api_secret);
3.制作上传表单,并将policy和signature等信息POST到指定地址
将这些信息填入到swfupload中的post_params字段。
var swfu; window.onload = function() { var settings = { flash_url : "swfupload/swfupload.swf", upload_url: "http://v0.api.upyun.com/<?php echo YNAME;?>", post_params: {"PHPSESSID" : "<?php echo session_id(); ?>","policy":"<?php echo $arcRow['policy']?>","signature":"<?php echo $arcRow['signature']?>",'Content-Type':'','key':'${filename}','Filename':'${filename}','bucket':"<?php echo $arcRow['bucket']?>",'path':"<?php echo $arcRow['path']?>"}, file_post_name: "file", file_size_limit : "50 MB", file_types : "*.*", file_types_description : "All Files", file_upload_limit : 100, file_queue_limit : 0, custom_settings : { progressTarget : "fsUploadProgress", cancelButtonId : "btnCancel" }, debug: false, // Button settings button_image_url: "swfupload/images/TestImageNoText_65x29.png", button_width: "65", button_height: "29", button_placeholder_id: "spanButtonPlaceHolder", button_text: '<span class="theFont">选择</span>', button_text_style: ".theFont { font-size: 16; }", button_text_left_padding: 12, button_text_top_padding: 3, // The event handler functions are defined in handlers.js file_queued_handler : fileQueued, file_queue_error_handler : fileQueueError, file_dialog_complete_handler : fileDialogComplete, upload_start_handler : uploadStart, upload_progress_handler : uploadProgress, upload_error_handler : uploadError, upload_success_handler : uploadSuccess, upload_complete_handler : uploadComplete, queue_complete_handler : queueComplete // Queue plugin event }; swfu = new SWFUpload(settings); };
最终效果:
完整源码下载:https://yunpan.cn/cYfyG89RtU8Rw (提取码:cfab)
您好,能否分享一下您的源码。非常感谢!
由于网盘过期,已无法下载