tp完美整合多图片上传
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/imghw/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/imghw/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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Learn about Python programming with introductory code examples Python is an easy-to-learn, yet powerful programming language. For beginners, it is very important to understand the introductory code examples of Python programming. This article will provide you with some concrete code examples to help you get started quickly. Print HelloWorldprint("HelloWorld") This is the simplest code example in Python. The print() function is used to output the specified content

PHP variables store values during program runtime and are crucial for building dynamic and interactive WEB applications. This article takes an in-depth look at PHP variables and shows them in action with 10 real-life examples. 1. Store user input $username=$_POST["username"];$passWord=$_POST["password"]; This example extracts the username and password from the form submission and stores them in variables for further processing. 2. Set the configuration value $database_host="localhost";$database_username="username";$database_pa

The simplest code example of Java bubble sort Bubble sort is a common sorting algorithm. Its basic idea is to gradually adjust the sequence to be sorted into an ordered sequence through the comparison and exchange of adjacent elements. Here is a simple Java code example that demonstrates how to implement bubble sort: publicclassBubbleSort{publicstaticvoidbubbleSort(int[]arr){int

Title: From Beginner to Mastery: Code Implementation of Commonly Used Data Structures in Go Language Data structures play a vital role in programming and are the basis of programming. In the Go language, there are many commonly used data structures, and mastering the implementation of these data structures is crucial to becoming a good programmer. This article will introduce the commonly used data structures in the Go language and give corresponding code examples to help readers from getting started to becoming proficient in these data structures. 1. Array Array is a basic data structure, a group of the same type

"Go Language Programming Examples: Code Examples in Web Development" With the rapid development of the Internet, Web development has become an indispensable part of various industries. As a programming language with powerful functions and superior performance, Go language is increasingly favored by developers in web development. This article will introduce how to use Go language for Web development through specific code examples, so that readers can better understand and use Go language to build their own Web applications. 1. Simple HTTP Server First, let’s start with a

How to use PHP to write the inventory management function code in the inventory management system. Inventory management is an indispensable part of many enterprises. For companies with multiple warehouses, the inventory management function is particularly important. By properly managing and tracking inventory, companies can allocate inventory between different warehouses, optimize operating costs, and improve collaboration efficiency. This article will introduce how to use PHP to write code for inventory warehouse management functions, and provide you with relevant code examples. 1. Establish the database before starting to write the code for the inventory warehouse management function.

Java Selection Sorting Method Code Writing Guide and Examples Selection sorting is a simple and intuitive sorting algorithm. The idea is to select the smallest (or largest) element from the unsorted elements each time and exchange it until all elements are sorted. This article will provide a code writing guide for selection sorting, and attach specific Java sample code. Algorithm Principle The basic principle of selection sort is to divide the array to be sorted into two parts, sorted and unsorted. Each time, the smallest (or largest) element is selected from the unsorted part and placed at the end of the sorted part. Repeat the above

Huawei Cloud Edge Computing Interconnection Guide: Java Code Samples to Quickly Implement Interfaces With the rapid development of IoT technology and the rise of edge computing, more and more enterprises are beginning to pay attention to the application of edge computing. Huawei Cloud provides edge computing services, providing enterprises with highly reliable computing resources and a convenient development environment, making edge computing applications easier to implement. This article will introduce how to quickly implement the Huawei Cloud edge computing interface through Java code. First, we need to prepare the development environment. Make sure you have the Java Development Kit installed (
