我正在将文件上传到 PHP 脚本。它处理并给出响应。我想在同一网页的 div 或框架中加载该响应。现在下面的脚本在空白网页中给出响应。请帮我解决这个问题。php:
<html>
<head>
<script type="text/javascript">
function init() {
if(top.uploadDone) top.uploadDone();
}
window.onload=init;
</script>
<body>
<?php
$fn = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);
if ($fn) {
file_put_contents(
'uploads/' . $fn,
file_get_contents('php://input')
);
echo "$fn uploaded";
exit();
}
else {
// form submit
$files = $_FILES['fileselect'];
//print $files['name'];
foreach ($files['error'] as $id => $err) {
if ($err == UPLOAD_ERR_OK) {
$fn = $files['name'][$id];
move_uploaded_file(
$files['tmp_name'][$id],
'uploads/' . $fn
);
if($id==1)
{
$filename = 'uploads/' . $fn;
$fp = fopen( $filename, "r" ) or die("Couldn't open $filename");
$line = fgets($fp);
fclose($fp);
$arr = split(",",$line);
for($i=2;$i< count($arr);$i++)
{
print '<input type="checkbox" name="traits" value="1">'.$arr[$i]."<br>";
}
}
}
}
}
?>
</body>
</html>
查询:
function init() {
document.getElementById("upload").onsubmit=function() {
document.getElementById("upload").target = "Analysis";
document.getElementById("Analysis").onload = uploadDone; }
}
function uploadDone() { //Function will be called when iframe is loaded
var ret = frames['Analysis'].document.getElementsByTagName("body")[0].innerHTML;
}
HTML 脚本:
<div id="content_column">
<form id="upload" action="upload.php" method="POST" enctype="multipart/form-data">
<fieldset>
<div id="Geno" style="display:none">
<strong>Select Genotypic File</strong>
<input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="300000" />
<div>
<input type="file" id="fileselect" name="fileselect[]" />
</div>
</div>
<P>
<div id="Peno" style="display:none">
<strong>Select Penotypic File</strong>
<div>
<input type="file" id="fileselect1" name="fileselect[]" />
</div>
</div>
<P>
<div id="Other" style="display:none">
<strong>Select Other Files*</strong>
<div>
<input type="file" id="fileselect2" name="fileselect[]" multiple="multiple" />
</div>
</div>
<div id="submitbutton" style="display:none">
<INPUT TYPE="Submit" VALUE="Upload" />
</div>
</fieldset>
</form>
<iframe id="Analysis" name="Analysis" src="" ></iframe>
</div>
提前谢谢你。.