主页 > 编程资料 > PHP >
发布时间:2014-12-08 作者:apizl 阅读:163次
html:
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
    <head>
        <title>图片异步上传</title>
    </head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://tool.apizl.com/static/boot/jquery-1.8.0.min.js"></script>
    <script>
        $(function() {
            $("#upload_file").change(function() {
                $("#uploadFrom").submit();
            });
        });

        function stopSend(str) {
            var im = "<img src='upload/images/" + str + "'>";
            $("#msg").append(im);
        }
    </script>
    <body>
        <div class="frm">
            <form name="uploadFrom" id="uploadFrom" action="upload.php" method="post"  target="tarframe" enctype="multipart/form-data">
                <input type="file" id="upload_file" name="upfile">
            </form>
            <iframe src=""  width="0" height="0" style="display:none;" name="tarframe"></iframe>
        </div>
        <div id="msg">
        </div>
    </body>
</html>


php:
<?php
$file=$_FILES['upfile'];
$name=rand(0,500000).dechex(rand(0,10000)).".jpg";
move_uploaded_file($file['tmp_name'],"upload/images/".$name);
//调用iframe父窗口的js 函数
echo "<script>parent.stopSend('$name');  </script>";
?>



文章由爱资料原创本文地址:https://www.apizl.com/archives/view-294-1.html,转载请以链接形式标明本文地址!
关键字词: