zoukankan      html  css  js  c++  java
  • 多张图片上传预览

    html:

    <html>
    <script src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>
    <script>
        $(function(){
            $('.pics').change(function(){
                $(this).parent().submit();
            });
        })
    </script>
    <body>
    
        <div>
            <form action="<?=$C->SITE_URL?>ylpic" method="post" target="hiddenFrameName" enctype="multipart/form-data">
                <label>图片1:</label> <input class="pics" type="file" name="pic" /><img id="img1" src="" width="80" height="80" style="display: none;" />
                <input type="hidden" name="tip" value="1">
            </form>
            <form action="<?=$C->SITE_URL?>ylpic" method="post" target="hiddenFrameName" enctype="multipart/form-data">
                <label>图片2:</label> <input class="pics" type="file" name="pic" /><img id="img2" src="" width="80" height="80" style="display: none;" />
                <input type="hidden" name="tip" value="2">
            </form>
            <form action="<?=$C->SITE_URL?>ylpic" method="post" target="hiddenFrameName" enctype="multipart/form-data">
                <label>图片3:</label> <input class="pics" type="file" name="pic" /><img id="img3" src="" width="80" height="80" style="display: none;" />
                <input type="hidden" name="tip" value="3">
            </form>
        </div>
    <form action="<?=$C->SITE_URL?>add" method="post" target="hiddenFrameName" id="frm">
        <input type="hidden" name="pic1" value="" id="pic1">
        <input type="hidden" name="pic2" value="" id="pic2">
        <input type="hidden" name="pic3" value="" id="pic3">
    </form>
    <iframe style="display: none" name='hiddenFrameName' id="hidden_frame"></iframe>
    
    </body>
    </html>

    ylpic.php

    <?php
    $tip=$_POST['tip'];
    if(isset($_FILES['pic']) && !empty($_FILES['pic']['tmp_name'])){
        $thumbname = number_format(time() + rand(1, 999));
        $upyun = new upyun($C->youpai_name, $C->youpai_id, $C->youpai_pw);
        $tmp=$_FILES['pic']['tmp_name'];
        $fn = '/'.$thumbname.'.jpg';
        $fh = fopen($tmp, 'r');
        $ret = $upyun->writeFile($fn, $fh, true);
        if ($ret) {
            $url=$C->up_url.$fn;
        }
    }
    ?>
    <body onLoad="doneLoading(parent)">
    </body>
    
    <script type="text/javascript">
        var tip='<?php echo $tip;?>';
        //在页面上显示刚刚上传成功的图像
        function doneLoading(theFrame) {
            var obj=theFrame.document.getElementById('img'+tip);
            var obj1=theFrame.document.getElementById('pic'+tip);
            obj.src='<?php echo $url;?>';
            obj.style.display='block';
            obj1.value='<?php echo $url;?>';
        }
    </script>

    注:iframe要通过parent才能找到它外面的DOM节点。

    add.php使用来将数据入库的。

    时不我待,不负韶华!立刻行动!不吃学习的苦就会吃生活的苦!
  • 相关阅读:
    修改Matlab 2012b默认工作路径
    win7,M​i​n​d​m​a​n​a​g​e​r​2​0​1​2使用模板时弹出Runtime error R6025解决方法
    Win7 Qt4.8.5+QtCreator2.8.0+mingw配置过程
    RabbitMQ介绍和延迟队列
    FastDFS介绍
    SpringMVC的工作流程
    spring mvc入参有Date类型
    spring 定时任务的 时间配置cron表达式
    Transactional介绍及使用
    spring cloud 集成rabbitMQ实现延时队列
  • 原文地址:https://www.cnblogs.com/zrp2013/p/3097353.html
Copyright © 2011-2022 走看看