先上效果图:
那个file按钮样式先忽略
点击选择图片(浏览),随便选一张图片
js代码如下
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
//上传图片立即预览
function previewimage(imgfile) {
var filextension = imgfile.value.substring(imgfile.value
.lastindexof( "." ), imgfile.value.length);
filextension = filextension.tolowercase();
if ((filextension != '.jpg' ) && (filextension != '.gif' )
&& (filextension != '.jpeg' ) && (filextension != '.png' )
&& (filextension != '.bmp' )) {
alert( "对不起,系统仅支持标准格式的照片,请您调整格式后重新上传,谢谢 !" );
imgfile.focus();
} else {
var path;
if (document.all) //ie
{
imgfile.select();
path = document.selection.createrange().text;
document.getelementbyid( "photo_info" ).innerhtml = "" ;
document.getelementbyid( "photo_info" ).style.filter = "progid:dximagetransform.microsoft.alphaimageloader(enabled='true',sizingmethod='scale',src=\\""
+ path + "\\")" ; //使用滤镜效果
} else //ff
{
path = window.url.createobjecturl(imgfile.files[0]); // ff 7.0以上
//path = imgfile.files[0].getasdataurl();// ff 3.0
document.getelementbyid( "photo_info" ).innerhtml = "<img id='img1' width='120px' height='100px' src='" +path+ "'/>" ;
//document.getelementbyid("img1").src = path;
}
}
}
|
html代码,其实不重要啦
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<div class = "form-group has-success has-feedback" >
<label for = "info_photo" class = "col-sm-2 control-label" >物品图片</label>
<div class = "col-sm-10" >
<span class = "btn btn-success btn-file" > 选择图片 <span
class = "glyphicon glyphicon-picture" aria-hidden= "true" ></span>
<input type= "file" name= "info_photo" value= "" id= "info_photo"
onchange= 'previewimage(this)' />
</span>
</div>
</div>
<div class = "form-group has-success has-feedback" >
<label for = "info_desc" class = "col-sm-2 control-label" ><span
style= "color: red;" >* </span>详细描述</label>
<div class = "col-sm-10" >
<textarea class = "form-control" rows= "5" id= "info_desc"
name= "info_desc" placeholder= "如需补充,请填写..." title= "可包含中文数字和常用字符" ></textarea>
<div id= "photo_info" class = "photo_info" ></div>
</div>
</div>
|
css代码就不上了啊
顺便补充一下thinkphp上传图片代码,把整个发布消息都拷过了算了
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
public function losething(){
$m =m( 'info' );
$m ->create();
$upload = new \\think\\upload(); // 实例化上传类
$upload ->maxsize = 3145728 ; // 设置附件上传大小
$upload ->exts = array ( 'jpg' , 'gif' , 'png' , 'jpeg' , 'bmp' ); // 设置附件上传类型
$upload ->rootpath = './public/' ;
$upload ->savepath = '/uploads/' ; // 设置附件上传目录
$upload ->autosub = false;
// 上传文件
$info = $upload ->upload();
if ( $info ) {
// 上传成功
foreach ( $info as $file ){
$m ->info_photo= $file [ 'savename' ];
}
}
$m ->create_time= date ( 'y-m-d h:i:s' ,time());
$m ->uid= $_session [ 'id' ];
$m ->username= $_session [ 'username' ];
/* $m->user_img=$_session['filename']; */
$m ->info_type= "寻物启事" ; //信息类型为失物
$lastid = $m ->add();
if ( $lastid ){
$this ->success( '发布成功' );
} else {
$this ->error( '发布失败,请先登录' );
}
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
相关文章
猜你喜欢
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-26 74
-
2025-05-26 56
-
.NET的DateTime函数获取上个月的起始和截止时间的方法
2025-05-29 61 -
2025-05-27 20
-
Ubuntu sudo报错command not found的解决方法
2025-05-25 37
热门评论