我需要一双额外的眼睛。我已经克服了很多次,但都没有成功。问题是getFilename
函数,顾名思义,它应该获取上传文件的文件名。不管我做什么,它似乎都不起作用,所以我一定错过了什么。
<?php
$data = $_GET["data"];
if($data)
{
echo '
<head>
<style>
.atklf
{
color: Red;
background: #292929;
border: 1px solid Red
}
</style>
</head>
<iframe name="fuh1" style="display: none;"></iframe>
<form
action="attklstformupldproc.php"
method="post"
target="fuh1"
enctype="multipart/form-data">
<table border="2" cellpadding="3" frame="void" style="color: red; width:100%;">
<tr>
<td>Priority:</td>
<td>Pirate: <span id="Pirreq"></span></td>
<td>Level:</td>
<td>Known Fleet Level:</td>
<td>X:</td>
<td>Y:</td>
</tr>
<tr>
<td>
<select id="Priority" class="atklf" name="Priority">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</td>
<td><input id="Pirate" class="atklf" name="Pirate" type="text" size="17" /></td>
<td><input id="Level" class="atklf" name="Level" type="text" size="4" /></td>
<td><input id="Fleet_Level" class="atklf" name="Fleet_Level" type="text" size="4" /></td>
<td><input id="XCoord" class="atklf" name="XCoord" type="text" size="5" /></td>
<td><input id="YCoord" class="atklf" name="YCoord" type="text" size="5" /></td>
</tr>
<tr>
<td>Outpost Level:</td>
<td>Known Wall Level:</td>
<td>Known Turret Level:</td>
<td colspan="2">Turret Types:</td>
<td>Group: <span id="Grpreq"></span></td>
</tr>
<tr>
<td><input id="Outpost_Level" class="atklf" name="Outpost_Level" type="text" size="4" /></td>
<td><input id="Knwn_wall_lvl" class="atklf" name="Knwn_wall_lvl" type="text" size="4" /></td>
<td><input id="Knwn_turr_lvl" class="atklf" name="Knwn_turr_lvl" type="text" size="4" /></td>
<td colspan="2" rowspan="2"><textarea id="Turret_Types" class="atklf" name="Turret_Types" rows="5" cols="16"></textarea></td>
<td rowspan="2">
<select id="Group" class="atklf" name="Group">
<option value="null">Pick a group</option>
<option value="General">General</option>
<option value="Sector 23">Sector 23</option>
<option value="Max Chaos">Max Chaos</option>
</select>
</td>
</tr>
<tr>
<td>Base Picture:</td>
<td colspan="2"><input id="Base_Picture" name="uploaded_bp" class="atklf" type="file" /></td>
</tr>
<tr>
<td colspan="6">Notes:</td>
</tr>
<tr>
<td rowspan="1" colspan="6"><textarea id="Notes" class="atklf" name="Notes" rows="7" cols="60"></textarea></td>
</tr>
<tr>
<td align="center"><input id="hlfsubmit" class="atklf" name="submit" value="Submit" type="submit" style="width: 90px;" onClick="assignVars()" /></td>
</tr>
<input type="button" class="atklf" value="Reset debug" onClick="resetDebug()"/>
<input type="button" class="normal" value="Get File name" onClick="getFilename1()"/>
</table>
</form>
<script type="text/javascript">
function resetDebug() {
document.getElementById("debug1").innerHTML = "";
}
function formFieldvalue(id) {
return document.getElementById(id).value;
}
function getFilename1() {
document.getElementById("debug1").innerHTML = formFieldvalue("Base_Picture");
}
Pri = "1";
Pir = "null";
Grp = "null";
function assignVars () {
Pri = document.getElementById("Priority").options[document.getElementById("Priority").selectedIndex].value;
Pir = encodeURIComponent(formFieldvalue("Pirate"));
if (formFieldvalue("Level")) {
Lvl = encodeURIComponent(formFieldvalue("Level"));
}
else {
Lvl = encodeURIComponent("?");
}
if (formFieldvalue("Fleet_Level")) {
Flv = encodeURIComponent(formFieldvalue("Fleet_Level"));
}
else {
Flv = encodeURIComponent("?");
}
if (formFieldvalue("XCoord")) {
XCd = encodeURIComponent(formFieldvalue("XCoord"));
}
else {
XCd = encodeURIComponent("?");
}
if (formFieldvalue("YCoord")) {
YCd = encodeURIComponent(formFieldvalue("YCoord"));
}
else {
YCd = encodeURIComponent("?");
}
if (formFieldvalue("Notes")) {
Nts = encodeURIComponent(formFieldvalue("Notes"));
}
else {
Nts = encodeURIComponent("?");
}
if (formFieldvalue("Outpost_Level")) {
Opl = encodeURIComponent(formFieldvalue("Outpost_Level"));
}
else {
Opl = encodeURIComponent("?");
}
if (formFieldvalue("Knwn_wall_lvl")) {
Kwl = encodeURIComponent(formFieldvalue("Knwn_wall_lvl"));
}
else {
Kwl = encodeURIComponent("?");
}
if (formFieldvalue("Knwn_turr_lvl")) {
Ktl = encodeURIComponent(formFieldvalue("Knwn_turr_lvl"));
}
else {
Ktl = encodeURIComponent("?");
}
if (formFieldvalue("Turret_Types")) {
Tty = encodeURIComponent(formFieldvalue("Turret_Types"));
}
else {
Tty = encodeURIComponent("?");
}
Grp = encodeURIComponent(formFieldvalue("Group"));
insertAttacktablerow();
}
if ( window.addEventListener ) {
window.addEventListener( "load", insertAttacktablerow, false );
}
else if ( window.attachEvent ) {
window.attachEvent( "onload", insertAttacktablerow );
}
function insertAttacktablerow() {
if (Pir != "null" && Grp != "null") {
document.getElementById("Pirreq").innerHTML = "";
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
//updateAttacktable();
document.getElementById("debug1").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/attacklist/attklstformproc.php?Pri=" + Pri + "&Pir=" + Pir + "&Lvl=" + Lvl + "&Flv=" + Flv + "&XCd=" + XCd + "&YCd=" + YCd + "&Nts=" + Nts + "&Opl=" + Opl + "&Kwl=" + Kwl + "&Ktl=" + Ktl + "&Tty=" + Tty + "&Grp=" + Grp + "&data=' . $data . '",true);
xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xmlhttp.send();
document.forms[0].reset();
}
else if (Pir == "null") {
document.getElementById("Pirreq").innerHTML = "(<b>required</b>)";
document.getElementById("Pirreq").style.color = "red";
}
else if (Grp == "null") {
document.getElementById("Grpreq").innerHTML = "(<b>required</b>)";
document.getElementById("Grpreq").style.color = "red";
}
}
</script>
<span id="debug1"></span>';
}
else
{
echo 'Restricted access.';
}
好的,所以我删除了最后一个答案,因为我终于花时间执行了您的代码。正如你所拥有的,它对我有效。
以下是我建议你做的。删除你的HTML和JavaScript,将它们放在一个独立的HTML文件中,然后加载到你的浏览器中。添加必要的标记以使其完整。(另外,你缺少了一个"身体"标签,并不是说这是你问题的根源。)
然后测试它。如果它有效,那么你的问题来自其他地方,而不是你提供的代码。你有页眉和页脚代码吗?
如果它不起作用,开始部分删除HTML和JavaScript,直到它起作用。使用它可以隔离错误的原因。
祝你好运。