【发布时间】:2016-06-14 11:02:01
【问题描述】:
我的文件上传器工作正常,现在我想在点击 Start Upload 时发送下拉列表的选定值和上传数据。
我阅读了以下 wiki,但没有运气。 How to submit additional form data
有人知道怎么做吗?
【问题讨论】:
标签: jquery jquery-file-upload blueimp asp.net-webpages
我的文件上传器工作正常,现在我想在点击 Start Upload 时发送下拉列表的选定值和上传数据。
我阅读了以下 wiki,但没有运气。 How to submit additional form data
有人知道怎么做吗?
【问题讨论】:
标签: jquery jquery-file-upload blueimp asp.net-webpages
我不像这里的大多数人那样聪明,但我试图实现相同类型的东西并让它为我工作。我可能无法很好地解释为什么,所以希望有人可以填补我不太了解的内容。
虽然我的实现有点不同,(我将为每个图像添加两个额外的输入)它可能会为您指明正确的方向。
这就是我想要做的......我想使用表单将文件添加到那里的服务器上的文件夹以及将其添加到数据库中。此外,对于每个图像,我也想选择要添加到数据库的其他字段。
如文档所述,我必须通过在表单模板中添加我的选择标记来修改索引页面上的表单。为简单起见,我只显示一个基本的选择标签和一个文本字段,而不是我将使用的 php 填充的选择标签。
确保为选择标签提供名称,并在每个字段的名称后包含 []。它将在 /server/php/index.php 中使用。
<td>
<td class="title"><label>SizeID: <input name="sizeID[]" required></label></td>
</td>
<td class="title"><label>Type: <select name="invTypeID[]">
<option value="1">Thing one</option>
<option value="2">Thing two</option>
</select></label>
</td>
</td>
在 /server/php/index.php 你将不得不修改
protected function handle_form_data()
和
protected function handle_file_upload()
对于我的特定实现,我将 handle_form_data 函数更改为以下内容。这样就可以将表单中的两个新字段的使用传递给 handle_file_upload 函数。
protected function handle_form_data($file, $index) {
$file->sizeID = @$_REQUEST['sizeID'][$index];
$file->invTypeID = @$_REQUEST['invTypeID'][$index];
}
接下来,我修改了 handle_file_upload 以匹配正确的 sql 语句,并调整了 bind_param() 函数以满足我的需要。
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
$index = null, $content_range = null) {
$file = parent::handle_file_upload(
$uploaded_file, $name, $size, $type, $error, $index, $content_range
);
if (empty($file->error)) {
$sql = 'INSERT INTO `'.$this->options['db_table']
.'` (`imgID`, `sizeID`, `invTypeID`)'
.' VALUES (?, ?, ?)';
$query = $this->db->prepare($sql);
$query->bind_param(
'sii',
$file->name,
$file->sizeID,
$file->invTypeID
);
$query->execute();
$file->id = $this->db->insert_id;
}
return $file;
}
我希望这会为您指明正确的方向。
【讨论】: