iframe callback方式文件上传

时间:2022-04-22 17:44:46

1、前端default.html

<!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>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script src="./qrcodejs/jquery.min.js"></script>
<script>
function js_upload_callback(filename){
document.getElementById('tip').innerHTML = filename;
}
</script>
</head> <body>
<iframe name="frmClean_iframe" style="display:none"></iframe>
<div id="tip"></div>
<form action="upload_file.php" method="post" enctype="multipart/form-data" target="frmClean_iframe">
<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

2、后台upload_file.php

<?php
echo '<script>window.parent.js_upload_callback( "'.$_FILES["file"]["name"].'");</script>';

  

相关文章