设为首页 加入收藏

TOP

php实现头像预览上传功能(一)
2017-10-10 10:48:18 】 浏览:9497
Tags:php 实现 头像 预览 上传 功能

最近在做php第二阶段的项目,需要用到头像上传的功能

我们要完成头像上传功能,一共要写两个php页面,第一个页面我们叫做touxiang.php,第二个页面我们叫做upload.php

1.touxiang.php

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 
 7 <link href="bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
 8 <script src="bootstrap-3.3.7-dist/js/jquery-1.11.2.min.js"></script>
 9 <script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
10 
11 <style type="text/css">
12 #yl{ width:200px; height:200px; background-image:url(img/avatar.png); background-size:200px 200px;}
13 #file{ width:200px; height:200px; float:left; opacity:0;}
14 .modal-content{ width:500px;}
15 .kk{ margin-left:130px;}
16 </style>
17 
18 </head>
19 
20 <body>
21 
22 
23 
24 <!-- 按钮触发模态框 -->
25 <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
26     上传头像
27 </button>
28 <!-- 模态框(Modal) -->
29 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
30     <div class="modal-dialog">
31         <div class="modal-content">
32             <div class="modal-header">
33                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
34                     &times;
35                 </button>
36                 <h4 class="modal-title" id="myModalLabel">
37                     上传头像
38                 </h4>
39             </div>
40             <div class="modal-body">
41                 <form id="sc" action="upload.php" method="post" enctype="multipart/form-data" target="shangchuan">
42     
43     <input type="hidden" name="tp" value="" id="tp" />
44     
45     <div id="yl" class="kk">
46         <input type="file" name="file" id="file" onchange="document.getElementById('sc').submit()" />
47     </div>
48     
49     
50     
51 </form>
52 
53 <iframe style="display:none" name="shangchuan" id="shangchuan">
54 </iframe>
55 
56             </div>
57             <div class="modal-footer">
58                 <button type="button" class="btn btn-default" data-dismiss="modal">关闭
59                 </button>
60                 <!--<button type="button" class="btn btn-primary">
61                     提交更改
62                 </button>-->
63                 
64             </div>
65         </div><!-- /.modal-content -->
66     </div><!-- /.modal -->
67 </div>
68 
69 
70 </body>
71 
72 <script type="t
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇时间查询的插件 下一篇yii2-验证规则,rules,判断条件

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目