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"; } ?>
本文出自 无忧之路 - 博客园