未定义的索引和函数没有 运行
undefined index and function doesn't run
我有类似这样的代码来启动脚本来发送订单。
include('../../auto/util.php');
if (!isValidFileName($_FILES['file-1']['tmp_name']) | !isValidFileName($_FILES['file-2']['tmp_name']))
{
echo "Invalid filename, <a href='index.php'>try again</a>.";
}
else if (count($_FILES) === 0)
{
echo "Your files failed to upload, likely because together they exceeded 15MB. Please submit the order manually to <a href=\"mailto:abc123@abc123.com\">abc123@abc123.com</a>";
}
else
{
newOrder_broker();
}
如果有文件上传,我会收到 file-1 和 file-2 的未定义索引错误。如果没有文件上传但代码有效并根据需要注入订单,我会得到同样的错误。
我的 HTML 看起来像这样:
<form id="docContainer" enctype="multipart/form-data" method="POST" action="newOrder_broker.php"
HTML 中的提交看起来像这样:
<div id="fb-submit-button-div" class="fb-item-alignment-left">
<button class="fb-button-special" id="fb-submit-button" style="background-image: url(theme/default/images/btn_submit.png);" onclick="checkShipTo();">Submit</button>
</div>
如果没有文件,我不希望进程停止。
表格HTML代码:
<body onload="checkCustoms()">
<!-- Start of the body content for CoffeeCup Web Form Builder -->
<?php include("alert.php"); ?>
<form id="docContainer" enctype="multipart/form-data" method="POST" action="newOrder_broker.php"
class="fb-100-item-column fb-toplabel selected-object" style="" data-form="manual_iframe">
<!-- // lots of form fields here here -->
<br />
<div id="item17" class="fb-item fb-50-item-column" style="opacity: 1; ">
<div class="fb-grouplabel">
<label id="item17_label_0" style="display: inline; ">
Upload front (Maximum size: 15MB)
</label>
<input type="checkbox" class="saveCheck" id="file-1-check" />
</div>
<div class="fb-button">
<input type="file" id="file-1" data-hint="" name="file-1-upload" onchange="readURL(this);" />
</div>
<br />
<img id="file-1-upload" src="#" alt="Preview (front)" width="200"/>
</div>
<div id="item31" class="fb-item fb-50-item-column" style="opacity: 1; ">
<div class="fb-grouplabel">
<label id="item31_label_0" style="display: inline; ">
Upload back (Maximum size: 15MB)
</label>
<input type="checkbox" class="saveCheck" id="file-2-check" />
</div>
<div class="fb-button">
<input type="file" id="file-2" data-hint="" name="file-2-upload" onchange="readURL(this);" />
</div>
<br />
<img id="file-2-upload" src="#" alt="Preview (back)" width="200" />
</div>
<div id="fb-submit-button-div" class="fb-item-alignment-left">
<button class="fb-button-special" id="fb-submit-button" style="background-image: url(theme/default/images/btn_submit.png);" onclick="checkShipTo();">Submit</button>
</div>
<button type="reset" onclick="localStorage.clear(); location.reload();">Reset</button>
<input type="hidden" name="fb_form_custom_html" />
<input type="hidden" name="fb_form_embedded" />
</form>
好的,所以我将名称更改为 "file-1" 和 "file-2"。我也添加了数组位置 [0] 但仍然得到:
Notice: Undefined index: file-1 in /home/prima2go/public_html/broker/sdp/newOrder_broker.php on line 6
Notice: Undefined index: file-2 in /home/prima2go/public_html/broker/sdp/newOrder_broker.php on line 6
Your files failed to upload, likely because together they exceeded 15MB. Please submit the order manually to abc123@primaatlanta.com
<input type="file" id="file-1" data-hint="" name="file-1" onchange="readURL(this);" />
一个
if (!isValidFileName($_FILES['file-1'][0]['tmp_name']) | !isValidFileName($_FILES['file-2'][0]['tmp_name']))
您的表单缺少 "file" 类型的输入。输入应如下所示:
<input type="file" value="">
如果没有这些输入,您的 PHP 将不会设置 $_FILES
数组,因此会出现您遇到的错误。
更新:
现在我看到了你所有的表格,我注意到你的文件输入是这样的:
<input type="file" id="file-1" name="file-1-upload" />
<input type="file" id="file-2" name="file-2-upload" />
这意味着您需要使用 name
属性通过 PHP 访问这些内容,如下所示:
$_FILES['file-1-upload']['tmp_name']
$_FILES['file-2-upload']['tmp_name']
我有类似这样的代码来启动脚本来发送订单。
include('../../auto/util.php');
if (!isValidFileName($_FILES['file-1']['tmp_name']) | !isValidFileName($_FILES['file-2']['tmp_name']))
{
echo "Invalid filename, <a href='index.php'>try again</a>.";
}
else if (count($_FILES) === 0)
{
echo "Your files failed to upload, likely because together they exceeded 15MB. Please submit the order manually to <a href=\"mailto:abc123@abc123.com\">abc123@abc123.com</a>";
}
else
{
newOrder_broker();
}
如果有文件上传,我会收到 file-1 和 file-2 的未定义索引错误。如果没有文件上传但代码有效并根据需要注入订单,我会得到同样的错误。
我的 HTML 看起来像这样:
<form id="docContainer" enctype="multipart/form-data" method="POST" action="newOrder_broker.php"
HTML 中的提交看起来像这样:
<div id="fb-submit-button-div" class="fb-item-alignment-left">
<button class="fb-button-special" id="fb-submit-button" style="background-image: url(theme/default/images/btn_submit.png);" onclick="checkShipTo();">Submit</button>
</div>
如果没有文件,我不希望进程停止。
表格HTML代码:
<body onload="checkCustoms()">
<!-- Start of the body content for CoffeeCup Web Form Builder -->
<?php include("alert.php"); ?>
<form id="docContainer" enctype="multipart/form-data" method="POST" action="newOrder_broker.php"
class="fb-100-item-column fb-toplabel selected-object" style="" data-form="manual_iframe">
<!-- // lots of form fields here here -->
<br />
<div id="item17" class="fb-item fb-50-item-column" style="opacity: 1; ">
<div class="fb-grouplabel">
<label id="item17_label_0" style="display: inline; ">
Upload front (Maximum size: 15MB)
</label>
<input type="checkbox" class="saveCheck" id="file-1-check" />
</div>
<div class="fb-button">
<input type="file" id="file-1" data-hint="" name="file-1-upload" onchange="readURL(this);" />
</div>
<br />
<img id="file-1-upload" src="#" alt="Preview (front)" width="200"/>
</div>
<div id="item31" class="fb-item fb-50-item-column" style="opacity: 1; ">
<div class="fb-grouplabel">
<label id="item31_label_0" style="display: inline; ">
Upload back (Maximum size: 15MB)
</label>
<input type="checkbox" class="saveCheck" id="file-2-check" />
</div>
<div class="fb-button">
<input type="file" id="file-2" data-hint="" name="file-2-upload" onchange="readURL(this);" />
</div>
<br />
<img id="file-2-upload" src="#" alt="Preview (back)" width="200" />
</div>
<div id="fb-submit-button-div" class="fb-item-alignment-left">
<button class="fb-button-special" id="fb-submit-button" style="background-image: url(theme/default/images/btn_submit.png);" onclick="checkShipTo();">Submit</button>
</div>
<button type="reset" onclick="localStorage.clear(); location.reload();">Reset</button>
<input type="hidden" name="fb_form_custom_html" />
<input type="hidden" name="fb_form_embedded" />
</form>
好的,所以我将名称更改为 "file-1" 和 "file-2"。我也添加了数组位置 [0] 但仍然得到:
Notice: Undefined index: file-1 in /home/prima2go/public_html/broker/sdp/newOrder_broker.php on line 6
Notice: Undefined index: file-2 in /home/prima2go/public_html/broker/sdp/newOrder_broker.php on line 6
Your files failed to upload, likely because together they exceeded 15MB. Please submit the order manually to abc123@primaatlanta.com
<input type="file" id="file-1" data-hint="" name="file-1" onchange="readURL(this);" />
一个
if (!isValidFileName($_FILES['file-1'][0]['tmp_name']) | !isValidFileName($_FILES['file-2'][0]['tmp_name']))
您的表单缺少 "file" 类型的输入。输入应如下所示:
<input type="file" value="">
如果没有这些输入,您的 PHP 将不会设置 $_FILES
数组,因此会出现您遇到的错误。
更新:
现在我看到了你所有的表格,我注意到你的文件输入是这样的:
<input type="file" id="file-1" name="file-1-upload" />
<input type="file" id="file-2" name="file-2-upload" />
这意味着您需要使用 name
属性通过 PHP 访问这些内容,如下所示:
$_FILES['file-1-upload']['tmp_name']
$_FILES['file-2-upload']['tmp_name']