tp完美整合多图片上传,网上找了很多控件均不能达到自己的要求,最后自己参考官方的例子结合自己对tp的不多认识,整合出来了适合自己用的,最近忙着项目,改天整理好了,单独分离出来上传分享,尽请期待哦; (暂时先把没改过的实例包发上来吧!有需要的朋友可以拿去参考)
更多技术文章请移步
http://www.dahuzhi.com
以下是部分代码:<br>
<br>
<!--多文件上传--><br>
<link>
<br>
<link>
<br>
<script></script><br>
<script></script><br>
<script></script><br>
<br>
<script><br />
$(document).ready(function() {<br />
$("#uploadify").uploadify({<br />
'uploader' : '/Public/duo_uploads/scripts/uploadify.swf', //上传按钮<br />
'script' : '/index.php/article/upload', //ajax请求文件<br />
'cancelImg' : '/Public/images/cancel.png', //关闭按钮图片地址<br />
'folder' : "../uploads/<{$time}>/", //时间<br />
'queueID' : 'fileQueue',<br />
'fileExt' : '*.jpg;*.gif;*.bmp;', //允许文件上传类型,和fileDesc一起使用.<br />
'fileDesc' : '*.jpg;*.gif;*.bmp;', //将不允许文件类型,不在浏览对话框的出现.<br />
'auto' : false,<br />
'multi' : true, //是否支持多文件上传<br />
'onComplete':function(event,queueId,fileObj,response,data){<br />
$('#info').html($('#info').html() + '<div class="img_box" ><img src="/static/imghwm/default1.png" data-src="/Public/Uploads/'+response+'" class="lazy" name="'+ response +'" style="max-width:90%" style="max-width:90%" alt="tp完美整合多图片上传" > <p onclick=del_img(this); >删除</script>
}
});
});
//删除文件
function del_img(whichSong)
{
//盒子对象
var info = document.getElementById('info');
//当前图片对象
var zi = whichSong.parentElement;
//图片名称
var path = zi.firstChild.name
//产生对象
var ajax=new XMLHttpRequest;
//生成事件处理器
ajax.onreadystatechange=function(){
if (ajax.readyState==4) { //判断请求状态为4完成的时候
if (ajax.status==200) { //判断服务器的http状态码等于200
//alert(ajax.responseText); //弹出服务器的响应
if(ajax.responseText)
{
//删除当前
info.removeChild(zi);
}
}
}
}
//打开链接
ajax.open('post','/index.php/article/img');
//设置http传输
ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//发送
ajax.send('action=del_img&path=' + path);
}
<script><br /> $(document).ready(function() {<br /> <br /> //所有的图片<br /> var imgs = $('#imgs').val();<br /> var str = '';<br /> //分割图片<br /> arr = imgs.split(',');<br /> <br /> //组合每个图片html<br /> for(var i = 0; i < arr.length; i++)<br /> {<br /> if(arr[i])<br /> {<br /> str += '<div class="img_box" ><img src="/static/imghwm/default1.png" data-src="/Public/Uploads/'+arr[i]+'" class="lazy" name="'+ arr[i] +'" style="max-width:90%" style="max-width:90%" alt="tp完美整合多图片上传" > <p onclick=del_img(this); >删除<input type="hidden" name="imgs[]" value="'+ arr[i] +'">';<br /> }<br /> }<br /> <br /> //所有图片html添加到已上传的图片盒子里<br /> $('#info').html(str);<br /> });<br /> </script>
//多文件上传<br>
function upload() <br>
{<br>
import("ORG.Net.Image3");<br>
if (!empty($_FILES)) <br>
{<br>
//获取文件名<br>
$tempFile = $_FILES['Filedata']['tmp_name'];<br>
//保存路径<br>
$targetPath = APP_PATH . 'Public/Uploads/';<br>
//新图片名<br>
$new_file_name = new_name( $_FILES['Filedata']['name']);<br>
//图片网站路径<br>
$targetFile = $targetPath . $new_file_name;<br>
<br>
//判断是否文件夹存在<br>
if(!is_dir($targetPath))<br>
mkdir($targetPath, 0777, true);<br>
<br>
//防止中文文件名乱码<br>
move_uploaded_file($tempFile,iconv('utf-8','gbk', $targetFile));<br>
<br>
//水印<br>
$water = 'water.gif';<br>
$img = new Image3();<br>
$img->param($targetFile)->water($targetFile,$water,9);<br>
//ajax返回图片名称<br>
echo get_relative_path($new_file_name);<br>
}<br>
}<br>
<br>
//图片模块<br>
public function img()<br>
{<br>
$c = D('class');<br>
$a = D('article');<br>
if($_POST['action'] == 'add')<br>
{<br>
//判断是否有上传多文件<br>
if($_POST['imgs'])<br>
{<br>
$_POST['img'] = '';<br>
foreach ($_POST['imgs'] as $v)<br>
{<br>
$_POST['img'] .= $v . ',';<br>
}<br>
}<br>
<br>
//加载上传类<br>
$file = static::get_file(2097152);<br>
//判断是否上传文件<br>
$_POST['simg'] = ($file) ? $file : '' ;<br>
$_POST['addtime'] = exec_time();<br>
//dump($_POST);die();<br>
//过滤数据并添加<br>
$a->create();<br>
if($a->add())<br>
static::success('添加成功', 3000, 1, 0);<br>
}<br>
<br>
//获取所有分类信息<br>
$data = $c->order('nos asc')->select();<br>
//格式化无线分类<br>
$data = static::get_class($data);<br>
$this->assign('data', $data);<br>
//时间输出<br>
$this->assign('time', date('Y-m-d', time()));<br>
$this->display();<br>
}
uploadify_v1.0.rar
( 62.44 KB 下载:882 次 )
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.