最近公司要做一个上传头像的功能,我们希望用户点击上传就实现了文件上传并不需要跳转页面了,下面我们就一起来看个例子吧。
可以批量进行添加上传,简单方便
| 代码如下 | 复制代码 |
|
<script><p><span>立即学习“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)”;</script> type="text/javascript" src="ajaxfileupload.js">
var str = ''; function ajaxFileUpload(){ $("#msg") .ajaxStart(function(){ $(this).show(); }); /* .ajaxComplete(function(){ $(this).hide(); }); */ $.ajaxFileUpload( { url:'up_deal.php', secureuri:false, fileElementId:'file1', dataType: 'text', //data:{name:'qinmi', id:'123'}, success: function(data){ if(data=='error'){
I-Shop购物系统
查看详情
部分功能简介:商品收藏夹功能热门商品最新商品分级价格功能自选风格打印结算页面内部短信箱商品评论增加上一商品,下一商品功能增强商家提示功能友情链接用户在线统计用户来访统计用户来访信息用户积分功能广告设置用户组分类邮件系统后台实现更新用户数据系统图片设置模板管理CSS风格管理申诉内容过滤功能用户注册过滤特征字符IP库管理及来访限制及管理压缩,恢复,备份数据库功能上传文件管理商品类别管理商品添加/修改/
0
$('#msg').html("上传失败"); }else{ www.111cn.net $('#msg').html("上传成功"); str += data+'@'; $('#fname').val(str); } } } ); return false; } |
|
up_deal.php
| 代码如下 | 复制代码 |
|
if ((($_FILES["file1"]["type"] == "image/gif") || ($_FILES["file1"]["type"] == "image/jpeg") || ($_FILES["file1"]["type"] == "image/bmp") || ($_FILES["file1"]["type"] == "image/pjpeg")) && ($_FILES["file1"]["size"] $extend = explode(".",$_FILES["file1"]["name"]); $key = count($extend)-1; $ext = ".".$extend[$key]; $newfile = time().$ext;
if(!file_exists('upload')){mkdir('upload');} move_uploaded_file($_FILES["file1"]["tmp_name"],"upload/" . $newfile); @unlink($_FILES['file1']); echo $newfile; }else { echo 'error'; } ?> |
|
其中需要用到ajaxfileupload.js 这个文件,
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号