zoukankan      html  css  js  c++  java
  • 简单的头像上传预览

    建一个简单的显示界面:

    <!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=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <form id="sc" action="shangchuan.php" target="hidden_frame" method="post" enctype="multipart/form-data">
        <div id="yl" style="margin-left:0px; 144px; height:170px; background-size:144px 170px; background-image:url(../chexiangqing/images/22.jpg)">
            <input type="file" name="file" style="144px; height:170px; float:left; opacity:0;" width="146"
        onchange="document.getElementById('sc').submit()"/> </div> <input type="button" value="保存"/> </form> <iframe style="display:none;" name="hidden_frame" id="hidden_frame"> </iframe> </body> <script type="text/javascript"> //回调函数 function showimg(aa) { var l = document.getElementById("yl"); l.style.backgroundImage = "url("+aa+")"; } </script> </html>

    php处理上传预览页面:

    <?php
       //上传文件限制
       if ((($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")|| ($_FILES["file"]["type"] == "image/png"))&& 
      ($_FILES["file"]["size"] < 10000000)) { //文件上传是否出错 if ($_FILES["file"]["error"] > 0) { echo "上传出错: " . $_FILES["file"]["error"] . "<br />"; } else { //判断文件是否已存在 $filename = "images/".$_FILES["file"]["name"]; $filename = iconv("UTF-8","gb2312",$filename); if (file_exists($filename)) { echo "<script language='javascript'>alert('文件已经存在!')</script>"; } else { //移动图片至保存路径,解决中文乱码问题 move_uploaded_file($_FILES["file"]["tmp_name"],$filename); echo "<script language='javascript'>parent.showimg('".$filename."')</script>"; } } } else { echo "上传失败"; } ?>
  • 相关阅读:
    MRC
    navigationcontroller手势翻页和navigationbar
    process monitor教程汇总
    Fixed: The Windows Process Activation Service service terminated with the following error: The system cannot find the file specified
    ObservableCollection 类
    玩转INotifyPropertyChanged和ObservableCollection
    在IIS中寄存服务
    WPF:为什么使用ContentPresenter.ContentSource而不是Content属性?
    正确理解WPF中的TemplatedParent
    Difference between List View and DataGrid in WPF
  • 原文地址:https://www.cnblogs.com/u1020641/p/6076320.html
Copyright © 2011-2022 走看看