php swfupload handlers.js,PHP swfupload图片文件上传实例代码

swfupload是一个flash插件它可以结合php来快速实现图片文件无刷新上传,同时还可以批量上传图片,下面我来给大家介绍PHP swfupload图片文件上传实例代码有需要了解的中参考.

index.php文件,代码如下:html>

SWFUpload Demos - SWFObject Demo

var swfu;

SWFUpload.onload = function () {

var settings = {

flash_url : "../swfupload/swfupload.swf",

upload_url : "upload.php",

post_params : {

"PHPSESSID" : "NONE",

"HELLO-WORLD" : "Here I Am",

".what" : "OKAY"

},

file_size_limit : "100 MB",

file_types : "*.jpg;*.gif;*.png;*.jpeg;",

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 : "XPButtonUploadText_61x22.png",

button_placeholder_id : "spanButtonPlaceholder",

button_width : 61,

button_height : 22,

// The event handler functions are defined in handlers.js

swfupload_loaded_handler : swfUploadLoaded,

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

// SWFObject settings

minimum_flash_version : "9.0.28",

swfupload_pre_load_handler : swfUploadPreLoad,

swfupload_load_failed_handler : swfUploadLoadFailed

};

swfu = new SWFUpload(settings);

}

SWFUpload

v2.2.0

SWFObject Demo

 This page demonstrates the SWFObject plugin.  Do each of the following (one at a time) to see the plugin work: 

  • Uninstall your Flash Player or install a version less than 9.0.28
  • Cause the SWF file to fail to load by deleting or renaming swfupload.swf (simulating a very slow or failed download)
  • Disable JavaScript

Each of these tests demontrate how these issues can be handled by SWFUpload and the SWFObject libraries.

Upload Queue

0 Files Uploaded

We're sorry.  SWFUpload could not load.  You must have JavaScript enabled to enjoy SWFUpload.

SWFUpload is loading. Please wait a moment...

SWFUpload is taking a long time to load or the load has failed.  Please make sure that the Flash Plugin is enabled and that a working version of the Adobe Flash Player is installed.

核心处理程序php代码,代码如下:if (isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {

$upload_file = $_FILES['Filedata'];

$file_info   = pathinfo($upload_file['name']);

$file_type   = $file_info['extension'];

$save        = 'image/' . md5(uniqid($_FILES["Filedata"]['name'])) . '.' . $file_info['extension'];

$name        = $_FILES['Filedata']['tmp_name'];

//开源代码phprm.com

if (!move_uploaded_file($name, $save)) {

exit;

}

//将数组的输出存起来以供查看

$fileName = 'test.txt';

$postData = var_export($file_info, true);

$file     = fopen('' . $fileName, "w");

fwrite($file,$postData);

fclose($file);

}

swfUpload注意事项

swfuplaod在上传时,会新开一个进程,和原来的进程不一致,要解决这个问题,需要指定session_id,然后在登录页面判断,如果有post过来的session_id,那么就用函数session_id($_POST['PHP_SESSIONID'])指定一下.

上传页的JS里面,可以获取当前的SESSION_ID的,例如上传页的JS中,代码如下:post_params: {"PHPSESSID": "<?php  echo session_id(); ?>"},

在验证的判断页,代码如下:if (isset($_POST["PHPSESSID"])) { session_id($_POST["PHPSESSID"]);}

这一段是网上的注释,在带有Session验证的网站后台中SWFUpload无法正常工作,这是因为SWFUpload在上传时相当于重新开辟了一个新的Session 进程,因此无法与原有程序的Session保持一致,这就需要在上传时传递原有程序的SessionID,根据它来“找回”其应有的Session.

转载随意,但请附上文章地址:-)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值