• web 文件上传 无刷新的方法 使用iframe


    <html>
    <script type="text/javascript" src="admin/view/js/jquery.min.js"></script>
    <body>
        <form action="t.php" encType="multipart/form-data" method="post"
            target="hidden_frame">
            <label for="file">Filename:</label> <input type="file" name="file"
                id="file" /> <br /> <input type="submit" name="submit"
                value="Submit" />
            <iframe name='hidden_frame' id="hidden_frame" style="display: none"></iframe>
            <input type="button" onclick="getValue()" value="获取图片地址">
        </form>
        <script type="text/javascript">
    function getValue(){ var imgUrl = $(window.frames["hidden_frame"].document).find("#imgUrl").val(); }   </script> </body> </html>
    <?php
    $savePath = $_SERVER ['DOCUMENT_ROOT'] . "/kx/upload/";
    require_once 'admin/util/GlobalTool.class.php';
    if ($_FILES ["file"] ["size"] < (5 * 1024 * 1024)) {
        if ($_FILES ["file"] ["error"] > 0) {
            echo "Return Code: " . $_FILES ["file"] ["error"] . "<br />";
        } else {
            $tool = new GlobalTool ();
            
            $fileName = GlobalTool::getUploadName ( $_FILES ["file"] ["name"] );
            
            move_uploaded_file ( $_FILES ["file"] ["tmp_name"], $savePath . $fileName );
            echo "<input type='hidden' id='imgUrl' value='/kx/upload" . $fileName . "'>";
        }
    } else {
        echo $_FILES ["file"] ["size"] . "<br>";
        echo "Invalid file";
    }
    
    ?>
  • 相关阅读:
    单片机开发 郭天祥
    OpenNI检测不到Kinect Camera和Kinect Audio了
    python中的类的成员变量以及property函数
    python lambda
    python中的括号以及元组和列表的区别
    python的self
    python exception的传递
    python的闭包
    函数里面定义函数
    在yum出问题的情况下安装某个rpm包的方法
  • 原文地址:https://www.cnblogs.com/wuyou/p/3463504.html
Copyright © 2020-2023  润新知