我正在尝试将一个或多个文件/图像添加到我的数据库中以进行每次检查/创建。
public function inspectieOpslaan($data){
$sql = "SELECT `id`
FROM `qa_inspection_document`
WHERE `part_id` = :part_id;";
$statement = $this->dbh->prepare($sql);
$statement->bindParam(':part_id', $_POST['part_id']);
$statement->execute();
$partID = $statement->fetchColumn();
if($statement->rowCount() == 0) {
$sql = "INSERT INTO `inspectiedocument_file` (title, inspection_requirement, inspection_resources, part_id, standard, extra_document, datum) VALUES (:title, :requirement, :resources, :partId, :standard, :extra_Document, :datum);";
$statement->bindParam(':title', $_POST['title']);
$statement->bindParam(':requirement', $_POST['inspection_requirement']);
$statement->bindParam(':resources', $_POST['inspection_resources']);
$statement->bindParam(':part_id', $_POST['part_id']);
$statement->bindParam(':standard', $_POST['standard']);
$statement->bindParam(':extra_Document', $_POST['extra_Document']);
$statement->bindParam(':datum', date('Y-m-d H:i:s', time()));
$statement->execute();
$partID = $this->dbh->lastInsertId();
}
$sql = "UPDATE `inspectiedocument_file` SET
`title` = :title,
`inspection_requirement` = :requirement,
`inspection_resources` = :resources,
`standard` = :standard,
`extra_document` = :status,
WHERE `part_id` = :part_id;";
$statement = $this->dbh->prepare($sql);
$statement->bindParam(':id', $_POST['part_id']);
$statement->bindParam(':title', $_POST['title']);
$statement->bindParam(':requirement', str2Bool($_POST['inspection_requirement']));
$statement->bindParam(':resources', str2Bool($_POST['inspection_resources']));
$statement->bindParam(':standard', str2Bool($_POST['standard']));
$statement->bindParam(':datum', $_POST['datum']);
$statement->execute();
if($data['aantalAfgekeurd'] > 0)
$resultaat = 'nok';
else
$resultaat = 'ok';
$temp = array();
$sql = "INSERT INTO `qa_purchase_order` (`part_id`, `order_number`, `row_number`, `quantity`, `inspected_quantity`, `approved_quantity`) VALUES (:partId, :orderNumber, :rowNumber, :quantity, :inspectedQuantity, :approvedQuantity)";
$statement = $this->dbh->prepare($sql);
$statement->bindParam(':partId', $data['partId']);
$statement->bindParam(':orderNumber', $data['inkooporderNummer']);
$statement->bindParam(':rowNumber', $data['regelNummer']);
$statement->bindParam(':quantity', $data['totaalAantal']);
$statement->bindParam(':inspectedQuantity', $data['aantalGecontroleerd']);
$statement->bindParam(':approvedQuantity', $data['aantalGoedgekeurd']);
$statement->execute();
$purchaseId = $this->dbh->lastInsertId();
$_SESSION['qa']['group'] = $purchaseId;
if(isset($_FILES['newDocuments'])){
$_FILES['documents'] = $_FILES['newDocuments'];
uploadFile('qa\inspections'); // <-- include.php
foreach($_SESSION['documents'] as $file)
{
$sql = "INSERT INTO `inspectiedocument_file` (title, inspection_requirement, inspection_resources, part_id, standard, extra_document, datum) VALUES (:title, :requirement, :resources, :partId, :standard, :extra_Document, :datum);";
$statement = $this->dbh->prepare($sql);
$statement->bindParam(':title', $sjabloon['titel']);
$statement->bindParam(':requirement', $sjabloon['inspectieEis']);
$statement->bindParam(':resources', $sjabloon['inspectieMiddelen']);
$statement->bindParam(':partId', $partId);
$statement->bindParam(':standard', $sjabloon['markeerStandaard']);
$statement->bindParam(':extra_Document', $file);
$statement->bindParam(':datum', date('Y-m-d H:i:s', time()));
$statement->execute();
}
}
}
然后在另一个文件夹中,我有以下代码将图像添加到数据库中(我没有包含其余字段的代码,因为它们工作正常)
<td class='label'>Extra informatie:</td>
<td>
<!-- -->
<table class="clean">
<tr>
<td class="none">
<table class="clean" id="newDocuments">
<tr>
<td class="none"><!-- Placeholder voor addDocument(); --></td>
<td class="none">
<input class="width" type="file" name="newDocuments[]" />
<img src="images/badge-circle-plus.png" onclick="addDocument('newDocuments');" alt="Document toevoegen" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
和这个JS代码:
<script>
function controleer()
{
var textNeeded = true;
var reacties = $('input[name^=newDocuments]');
var bestaandeReacties = $('table#documents tr').length - 1; // - 1 is voor th
for(var i = 0; i < reacties.length; i++) {
if(reacties.eq(i).val() == '' && bestaandeReacties <= 0) {
reacties.eq(i).addClass('error');
setDocMelding = true;
} else {
textNeeded = false;
}
}
}
</script>
最后,在我的观点中,我有以下几点:
if(isset($sjabloon['extra_document']) && !empty($sjabloon['extra_document']))
{
$dochtml .= '<tr>';
$dochtml .= '<td class="label">Extra document:</td>';
$dochtml .= '<td><a target="_blank" href="'. $url .'uploads/qa/sjabloon/'. urlencode($sjabloon['extra_document']) .'">'. $sjabloon['extra_document'] .'</a></td>';
$dochtml .= '</tr>';
}
最后所有的价值都被添加到DATABSE预期的图像,它没有记录我上传了多少imgae,他们在数据库中没有价值,我做错了什么?