php产品细节图多图上传示例代码 无刷新
前台文件代码
upload.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>产品细节图多图上传示例代码 无刷新</title>
<style>
.filepath{width:300px;}
.uploadinfo{color:#009900;}
</style>
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
function process(v){
if(v=="inform"){
document.addimgform.action="do_upload.php";
$("form").attr("target","fileUp");
}
document.addimgform.submit();
} $(document).ready(function(){ ////////////////////
$('#add_gallery').click(function(){
$("#gallery").append('<div class="addinput"><a href="javascript:;" class="remove_gallery">[-]</a> <input name="filepath[]" id="textpath" class="textpath" type="text" value="" /> <input type="file" name="img_gallery[]" id="img_gallery" class="filepath" /> <span class="spanimg"></span></div>');
}); ////////////////////
$(document).on("click",".remove_gallery",function(){$(this).parent(".addinput").remove();}); ////////////////////
$(document).on("change",".filepath",function(){
var route=$(this).val();
$(this).parents(".addinput").find(".textpath").val(route);
}); ////////////////////
$(document).on("click",".delimg",function(){
id = $(this).attr("rel");
url = $(this).attr("rev");
path = $(this).attr("rep");
name = $(this).parents(".addinput").find(".filepath").val();
$.post
(
"do_upload.php",
{imgid:id,imgurl:url,imgpath:path},
function(){
alert('图片 '+name+' 已删除!');
},
"html"
);
$(this).parents(".addinput").remove();
}); //////////////////// }); </script> </head> <body> <!--<form id="addimgform" name="addimgform" target="fileUp" enctype="multipart/form-data" action="do_upload.php" method="post">-->
<form id="addimgform" name="addimgform" enctype="multipart/form-data" action="product.php" method="post">
<fieldset>
<legend>产品上传</legend> 产品名:<input name="proname" type="text" value="" /><br /><br />
价 格:<input name="price" type="text" value="" /><br /><br /> <fieldset>
<legend>图片上传</legend> <div id="gallery">
<div class="addinput"><a href="javascript:;" class="remove_gallery">[-]</a> <input name="filepath[]" id="textpath" class="textpath" type="text" value="" /> <input type="file" name="img_gallery[]" id="img_gallery" class="filepath" /> <span class="spanimg"></span></div>
</div>
<a href="javascript:;" id="add_gallery">[+]</a>
<input name="upimg" type="submit" value="上传" id="upimg" onclick="process('inform')">
<span class="uploadinfo"></span>
</fieldset>
<iframe style="border:0px;" width="0px" height="0px" name="fileUp"></iframe> <script>
function notice_success(i,url,path,info){
$("#gallery .textpath").eq(i).val(url);
$("#gallery .spanimg").eq(i).html(info+'<img src="'+url+'" style="width:60px; height:60px;" align="absmiddle" /> <a class="delimg" href="javascript:;" rel="'+i+'" rev="'+url+'" rep="'+path+'">删除</a> ');
}
function notice_failure(info){
$("#gallery .spanimg").eq(i).html(info);
}
</script> <input name="submit" type="submit" value="提交" id="submit"> </fieldset> </form>
</body>
</html>
后台文件代码
do_upload.php
<?php
$basedir = dirname(__FILE__).'/'.date('Y-m-d');
$new_folder = str_replace('\\','/',$basedir);
if(file_exists($new_folder)){
//echo 'exists';
}else{
mkdir($new_folder, 0777);
}
?>
<?php
if (isset($_POST['imgid']) && isset($_POST['imgurl']) && isset($_POST['imgpath'])){
if(file_exists($_POST['imgpath'])){
$thepath = str_replace('/','\\',$_POST['imgpath']);
unlink($thepath);
}else{
echo '未找到相关文件';
}
}
if(!empty($_FILES)){
for ($i=0;$i<count($_FILES['img_gallery']['tmp_name']);$i++){
//$file_name = iconv('utf-8', 'gb2312', $_FILES['img_gallery']['name']);//在utf8编码下可以防止中文乱码
$upfile = $new_folder."/".$_FILES['img_gallery']['name'][$i];//此处路径换成你的
$imgpath = 'http://'.$_SERVER['SERVER_NAME'].'/images/'.date('Y-m-d').'/'.$_FILES['img_gallery']['name'][$i];//上传后的图片url
if(move_uploaded_file($_FILES['img_gallery']['tmp_name'][$i],$upfile)){
//echo "第".($i+1)."张图片上传成功<br>";
$info = "第".($i+1)."张图片上传成功! ";
//此处进行数据库操作
?>
<script>parent.notice_success('<?php echo $i;?>','<?php echo $imgpath;?>','<?php echo $upfile;?>','<?php echo $info;?>');</script>
<?php
@unlink($_FILES["img_gallery"]["tmp_name"][$i]);
}
else{
$info = "第".($i+1)."张图片上传不成功! ";
?>
<script>parent.notice_failure('<?php echo $info;?>');</script>
<?php
}
}
}
?>
打完收工!
php产品细节图多图上传示例代码 无刷新的更多相关文章
- js 实现 input type="file" 文件上传示例代码
在开发中,文件上传必不可少但是它长得又丑.浏览的字样不能换,一般会让其隐藏点其他的标签(图片等)来时实现选择文件上传功能 在开发中,文件上传必不可少,<input type="file ...
- HTML5实现多文件的上传示例代码
[转自] http://www.jb51.net/html5/136791.html 主要用到的是<input>的multiple属性 代码如下: <input type=" ...
- mui开发app之多图压缩与上传(仿qq空间说说发表)
欲实现效果图 提出需求点: 用户可自由添加删除替换多张图片,并且显示相应缩略图,限制为8张 用户可选择压缩图或直接上传原图功能 返回提醒用户会丢失填写的信息 下面一个个实现上述需求,从简单到复杂: 需 ...
- jQuery AJAX 网页无刷新上传示例
新年礼,提供简单.易套用的 jQuery AJAX 上传示例及代码下载.后台对文件的上传及检查,以 C#/.NET Handler 处理 (可视需要改写成 Java 或 PHP). 有时做一个网站项目 ...
- UEditor之实现配置简单的图片上传示例
UEditor之实现配置简单的图片上传示例 原创 2016年06月11日 18:27:31 开心一笑 下班后,阿华到楼下小超市买毛巾,刚买完出来,就遇到同一办公楼里另一家公司的阿菲,之前与她远远的有过 ...
- JAE京东云引擎Git上传管理代码教程和京东云数据库导入导出管理
文章目录 Git管理准备工作 Git工具上传代码 发布代码装程序 mywebsql管理 京东云引擎小结 JAE京东云引擎是京东推出的支持Java.Ruby.Python.PHP.Node.js多语 ...
- WebLogic 任意文件上传远程代码执行_CVE-2018-2894漏洞复现
WebLogic 任意文件上传远程代码执行_CVE-2018-2894漏洞复现 一.漏洞描述 Weblogic管理端未授权的两个页面存在任意上传getshell漏洞,可直接获取权限.Oracle 7月 ...
- 【转载】兼容php5,php7的cURL文件上传示例
转载来自: http://www.huanlinna.com/2016/06/25/coding/php5-php7-upload-demo-via-curl.html https://segment ...
- git上传项目代码到github
参考: git学习——上传项目代码到github github上传时出现error: src refspec master does not match any解决办法 git 上传本地文件到gith ...
随机推荐
- Junit : how to add listener, and how to extends RunListener to override behaviors while failed
http://junit.sourceforge.net/javadoc/org/junit/runner/notification/RunListener.html org.junit.runner ...
- 深度学习基础——Epoch、Iteration、Batchsize
原文地址:https://www.cnblogs.com/Johnny-z6951/p/11201081.html 梯度下降是一个在机器学习中用于寻找较佳结果(曲线的最小值)的迭代优化算法.梯度的含义 ...
- Sublime text3 Version 3.2.2, Build 3211破解
一.修改hosts hosts地址: C:\Windows\System32\drivers\etc #sublimetext 127.0.0.1 www.sublimetext.com 127.0. ...
- 嵌套的JsonObject与JSONArray的取值---JSON中嵌套JSONArray
在复杂的JSON数据的格式中,往往会对JSON数据进行嵌套,这样取值会比之前的取值稍微复杂一点,但是只要思路清晰,其实取法还是一样的.就跟if else语句一样,如果if中套if,if中再套if,写的 ...
- Stream parallel并行流的思考
1.并行流并不一定能提高效率,就和多线程并不能提高线程的效率一样 因为引入并行流会引起额外的开销,就像线程的频繁上下文切换会导致额外的性能开销一样,当数据在多个cpu中的处理时间小于内核之间的传输时间 ...
- python学习之深浅拷贝
4.2 深浅拷贝 4.2.1 认识 首先应该知道python中变量在内存中是怎么存放的! 在python中,变量与变量的值占用不同的内存.变量占用的内存,并非直接存储数值,而存储的是值在内存中的地址. ...
- tensorflow keras导包混用
tensoboard 导入:导入包注意 否者会报错 :keras FailedPreconditionError: Attempting to use uninitialized value trai ...
- 【神经网络与深度学习】用训练好的caffemodel来进行分类
现在我正在利用imagenet进行finetune训练,待训练好模型,下一步就是利用模型进行分类.故转载一些较有效的相关博客. 博客来源:http://www.cnblogs.com/denny402 ...
- vue调用组件,组件回调给data中的数组赋值,报错Invalid prop type check failed for prop value. Expecte
报错信息: 代码信息:调用一个tree组件,选择一些信息 <componentsTree ref="typeTreeComponent" @treeCheck="t ...
- react 中 EventEmitter 事件总线机制
此机制可用于 react 中兄弟组件中的通信 npm install events -S 事件总线: // eventBus.js import {EventEmitter} from 'events ...