swfupload 实例 php,文件上传之SWFUpload插件(代码)

下面通过一段代码给大家演示下,主要分为1.前台文件index.html和 2.后台文件upload.php。具体代码如下所示:

1.前台文件index.html

SWFUpload

var swfu;

window.onload = function() {

var settings = {

flash_url : "swfupload/swfupload.swf",

upload_url: "upload.php", // 后台文件

post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},

file_size_limit : "100 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_image_url: "images/TestImageNoText_65x29.png", // Flash样式图片文件

button_width: "65",

button_height: "29",

button_placeholder_id: "spanButtonPlaceHolder",

button_text: '浏览',

button_text_style: ".theFont { font-size: 16; }",

button_text_left_padding: 12,

button_text_top_padding: 3,

// 句柄设置

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

};

swfu = new SWFUpload(settings);

};

点击“浏览”按钮,选择您要上传的文档文件后,系统将自动上传并在完成后提示您。

请勿上传包含中文文件名的文件!

快速上传

0 个文件已上传
Hanization By Leo.C,

2.后台文件upload.php

// 传递session值(由于Flash与session不兼容,只能通过参数传递获取)

if (isset($_POST["PHPSESSID"])) {

session_id($_POST["PHPSESSID"]);

} else if (isset($_GET["PHPSESSID"])) {

session_id($_GET["PHPSESSID"]);

}

session_start();

// 设置POST最大值

$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");

echo "POST exceeded maximum allowed size.";

exit(0);

}

// 基本设置

$save_path = getcwd() . "/file/";             // 文件上传位置

$upload_name = "Filedata";

$max_file_size_in_bytes = 2147483647;          // 2GB

$extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // 允许文件类型

$valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // 文件名规则

// 其他变量

$MAX_FILENAME_LENGTH = 260;

$file_name = "";

$file_extension = "";

$uploadErrors = array(

0=>"文件上传成功",

1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",

2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",

3=>"上传的文件仅为部分文件",

4=>"没有文件上传",

6=>"缺少临时文件夹"

);

// 检测文件是否上传正确

if (!isset($_FILES[$upload_name])) {

HandleError("No upload found in \$_FILES for " . $upload_name);

exit(0);

} else if (isset($_FILES[$upload_name]["error"]) && $_FILES[$upload_name]["error"] != 0) {

HandleError($uploadErrors[$_FILES[$upload_name]["error"]]);

exit(0);

} else if (!isset($_FILES[$upload_name]["tmp_name"]) || !@is_uploaded_file($_FILES[$upload_name]["tmp_name"])) {

HandleError("Upload failed is_uploaded_file test.");

exit(0);

} else if (!isset($_FILES[$upload_name]['name'])) {

HandleError("File has no name.");

exit(0);

}

// 检测文件尺寸

$file_size = @filesize($_FILES[$upload_name]["tmp_name"]);

if (!$file_size || $file_size > $max_file_size_in_bytes) {

HandleError("File exceeds the maximum allowed size");

exit(0);

}

if ($file_size <= 0) {

HandleError("File size outside allowed lower bound");

exit(0);

}

// 检测文件名字为空

$file_name = preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));

if (strlen($file_name) == 0 || strlen($file_name) > $MAX_FILENAME_LENGTH) {

HandleError("Invalid file name");

exit(0);

}

// 检测重名文件

if (file_exists($save_path . $file_name)) {

HandleError("File with this name already exists");

exit(0);

}

// 检测后缀名

$path_info = pathinfo($_FILES[$upload_name]['name']);

$file_extension = $path_info["extension"];

$is_valid_extension = false;

foreach ($extension_whitelist as $extension) {

if (strcasecmp($file_extension, $extension) == 0) {

$is_valid_extension = true;

break;

}

}

if (!$is_valid_extension) {

HandleError("Invalid file extension");

exit(0);

}

// 保存文件

if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {

HandleError("文件无法保存.");

exit(0);

}

// 成功输出

echo "File Received";

exit(0);

function HandleError($message) {

header("HTTP/1.1 500 Internal Server Error");

echo $message;

}

?>

以上代码就是实现文件上传之SwFUpload插件的全部内容,希望大家喜欢。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/557840.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Vue报错:Unknown custom element: router-view - did you register the component correctly页面中不显示链接

Vue报错&#xff1a;Unknown custom element: router-view - did you register the component correctly vue-router应用到组件中时报错&#xff1a; Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide t…

java 中 的 =,java 中的 |=、=、^=

关于 | 运算符&#xff1a;| 运算符和 这一类的运算符一样&#xff0c;拆解开就是 a a | bint a 5; // 0000 0101int b 3; // 0000 0011a | b; // 0000 00111具体规则为&#xff1a;两个二进制对应位为0时该位为0&#xff0c;否则为1。拿5的二进制 0000 0101 和 3的二进制 …

Vue页面跳转后不显示问题

Vue页面跳转后不显示问题 必须要添加 path前面要有/

HDFS剩余空间大小的Java接口,java api获取hdfs索引大小

java api获取hdfs目录大小1. hadoop fs -dus 的源码&#xff1a;public static void dus(String src,Configuration conf) throws IOException {Path srcPath new Path(src);FileSystem srcFs srcPath.getFileSystem(conf);FileStatus status[] srcFs.globStatus(new Path(s…

Windows之node.js安装

Windows之node.js安装 1.下载node.js&#xff0c; 下载地址&#xff1a;https://nodejs.org/zh-cn/download/ 选择windows安装 2.安装&#xff0c;双击软件图标——接受协议——选择安装路径——选择安装配置&#xff08;如下图&#xff09;——等待安装——完成安装。 自动帮…

php开发工具 debug,php开发性能调试工具xdebug

调试是一门艺术&#xff0c;在项目开发过程中&#xff0c;调试是很关键的一步。php中一般使用die,exit()控制断点并使用echo、print_r()、var_dump()、printf()输出结果来调试。一般情况下以上就可以满足开发者调试的目的了。下面来介绍一下xdebug工具。Xdebug是一个开放源代码…

Windows之vue-cli安装和vue项目快速搭建

Windows之vue-cli安装和vue项目快速搭建 1.提前安装好node.js&#xff0c; 安装步骤&#xff1a;https://blog.csdn.net/qq_43842093/article/details/116918715 2.nodejs安装好后&#xff0c;默认带有npm 3.使用npm安装vue-cli cnpm instal1 vue-cli-g #测试是否安装成功#查看…

java 字符流 utf8,JAVA基础(字符流设置编码读写字符)

1&#xff0c;使用指定的码表读写字符FileReader是使用默认码表读取文件, 如果需要使用指定码表读取, 那么可以使用InputStreamReader(字节流,编码表)FileWriter是使用默认码表写出文件, 如果需要使用指定码表写出, 那么可以使用OutputStreamWriter(字节流,编码表)【1】 代码分…

Vue概述和各种前端框架

1、概述 Vue (读音 /vjuː/&#xff0c;类似于 view) 是一套用于构建用户界面的渐进式JavaScript框架&#xff0c;发布于2014年2月。与其它大型框架不同的是&#xff0c;Vue 被设计为可以自底向上逐层应用。Vue 的核心库只关注视图层&#xff0c;方便与第三方库&#xff08;如…

Mvvm、第一个Vue程序、Vue基本语法

一、MVVM概述 1.1、什么是MVVM MVVM&#xff08;Model-View-ViewModel&#xff09;是一种软件设计模式&#xff0c;由微软WPF&#xff08;用于替代WinForm&#xff0c;以前就是用这个技术开发桌面应用程序的&#xff09;和Silverlight&#xff08;类似于Java Applet&#xff…

matlab中计算不等式的解,matlab解不等式

MATLAB求解非线性规划good (1)_理学_高等教育_教育专区。数学建模课...x4 ? x5 MATLAB 程序如下: f[1; 2; 3; 1; 1]; intcon[1 2 3 4 5]; A[-2 -3 -5 -4 -7; -1 -1 -4 -2 -2]; %改变不等式符号 ......VUB (线性不等式约束) (线性等式约束) (非线性不等式约束) (非线性等式约束…

支付宝沙箱支付步骤

蚂蚁金服开放平台文档中心——网页移动应用——开放能力——支付能力——电脑网站支付下载SDK&Demo调试Demo文档中心——网页移动应用——开发工具——沙箱环境生成公钥和私钥&#xff0c;设置应用公钥在Demo中添加APPID&#xff0c;应用私钥和支付宝公钥支付宝网关

matlab 一维 平滑,一维加噪信号的平滑处理(3)

%-------------------------------------------------------------------------- % 调用medfilt1函数对加噪正弦波信号进行平滑处理 %-------------------------------------------------------------------------- %*****************产生加噪正弦波信号&#xff0c;绘制加噪波…

Module build failed: Error: Node Sass version 5.0.0 is incompatible with ^4.0.0.

Module build failed: Error: Node Sass version 5.0.0 is incompatible with ^4.0.0. node-sass版本过高导致的&#xff0c;卸载重装低版本: 1.卸载已安装版本 npm uninstall node-sass 2.安装 npm install node-sass4.14.1 3.npm run dev

php高中级程序员面试题,PHP 程序员面试笔试常考面试题精讲

最近假期的原因&#xff0c;决定在chat开了这门课&#xff0c;希望对你有帮助。主要总结汇总了 PHP 面试过程中最爱问的几道面试题。这些面试题可以很好的帮助面试者准备&#xff0c;并让你在面试过程中很好的回答这些面试题&#xff0c;轻松拿下 offer。由于一个 PHP 应聘者面…

Gompertz模型绘图 matlab,Logistic模型matlab求解

Logistic模型求解怎么用matlab求解啊&#xff1f;悬赏分&#xff1a;100 - 解决时间&#xff1a;2008-11-17 23:09已知x0:1:12y[43.65 109.86 187.21 312.67 496.58 707.65 960.25 1238.75 1560.00 1824.29 2199.00 2438.89 2737.71]yL/(1a*exp(-k*x))利用线性回归模型所得到的…

vue错误:vue.esm.js?efeb:628 [Vue warn]: Error in render: “TypeError: Cannot read property ‘matched‘ of

控制台出现这个错误vue.esm.js?efeb:628 [Vue warn]: Error in render: “TypeError: Cannot read property ‘matched’ of undefined” found in —> at src/App.vue 错误&#xff1a; 原因&#xff1a; 这里错误&#xff0c;必须使用&#xff1a; vue实例里固定路由器…

php unserialize 实例,PHP ArrayIterator unserialize()用法及代码示例

ArrayIterator::unserialize()函数是PHP中的一个内置函数&#xff0c;用于反序列化序列化对象。用法:void ArrayIterator::unserialize( string $serialized )参数&#xff1a;此函数接受单个参数$serialized&#xff0c;该参数保存序列化数组迭代器对象。返回值&#xff1a;此…

阿里云成长记的一篇文章《阿里云的这群疯子》

阿里云成长记的一篇文章&#xff0c;叫做《阿里云的这群疯子》&#xff0c;文章中记述着阿里云是如何一步步走到今天的&#xff0c;今天的成功源于昨日的付出&#xff0c;机会只留给有准备的人&#xff0c;勤奋的聪明人。 《阿里云的这群疯子》 世事安稳&#xff0c;岁月静好。…

自动摘要php,phpcms修改手动摘要255字符、自动摘要200字符及取消自动摘要

效果展示&#xff1a;phpcms修改手动摘要255字符、自动摘要200字符及取消自动摘要phpcms v9手动摘要默认255个字符的修改方法&#xff1a;登陆后台-->内容-->模型管理-->文章模型-->字段管理-->摘要-->修改-->字符长度取值范围-->将255修改为你想要的数…