98 lines
3.4 KiB
PHP
98 lines
3.4 KiB
PHP
<?php
|
|
include('include/headscript.php'); ?>
|
|
<?php
|
|
if (!empty($_FILES['doc'])) {
|
|
// File upload configuration
|
|
if (isset($_POST["idtrftd"])) {
|
|
$idtrftd = $_POST["idtrftd"];
|
|
}
|
|
if (isset($_POST["iddata_td"])) {
|
|
$idtd = $_POST["iddata_td"];
|
|
}
|
|
if (isset($_POST["filedescription"])) {
|
|
$filedescription = $_POST["filedescription"];
|
|
} else {
|
|
$filedescription = "";
|
|
}
|
|
$targetDir = "uploadtddocuments/";
|
|
$allowTypes = array('pdf', 'doc', 'xls', 'xlsx', 'docx', 'jpg');
|
|
|
|
$docs_arr = array();
|
|
foreach ($_FILES['doc']['name'] as $key => $val) {
|
|
$doc_name = $_FILES['doc']['name'][$key];
|
|
$tmp_name = $_FILES['doc']['tmp_name'][$key];
|
|
$size = $_FILES['doc']['size'][$key];
|
|
$type = $_FILES['doc']['type'][$key];
|
|
$error = $_FILES['doc']['error'][$key];
|
|
|
|
// File upload path
|
|
$code = time();
|
|
$fileName = basename($_FILES['doc']['name'][$key]);
|
|
$fileName = $idtd . '-' . $code . $fileName;
|
|
$targetFilePath = $targetDir . $fileName;
|
|
|
|
|
|
|
|
// Check whether file type is valid
|
|
$fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);
|
|
|
|
if (in_array($fileType, $allowTypes)) {
|
|
|
|
// Store images on the server
|
|
//echo $fileName;
|
|
|
|
if (move_uploaded_file($_FILES['doc']['tmp_name'][$key], $targetFilePath)) {
|
|
|
|
$docs_arr[] = $targetFilePath;
|
|
|
|
$InsertQuery = new WA_MySQLi_Query($cmctrfdb);
|
|
$InsertQuery->Action = "insert";
|
|
$InsertQuery->Table = "tdfileattached";
|
|
$InsertQuery->bindColumn("iddata_td", "i", "$idtd", "WA_DEFAULT");
|
|
$InsertQuery->bindColumn("filename_fileattached", "s", "$fileName", "WA_DEFAULT");
|
|
$InsertQuery->bindColumn("description_fileattached", "s", "$filedescription", "WA_DEFAULT");
|
|
$InsertQuery->saveInSession("");
|
|
$InsertQuery->execute();
|
|
$InsertGoTo = "";
|
|
$InsertQuery->redirect($InsertGoTo);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Generate gallery view of the images
|
|
/*if(!empty($docs_arr)){ ?>
|
|
<ul>
|
|
<?php foreach($docs_arr as $doc_src){ ?>
|
|
<!-- SHOW LINK -->
|
|
<a href="<?php echo $doc_src; ?>" target="_blank"><?php echo $doc_src; ?></a>
|
|
<?php } ?>
|
|
</ul>
|
|
<?php }*/
|
|
// LIST ALL UPLOADED FILES INSIDE TABLE
|
|
$filenamelist = new WA_MySQLi_RS("filenamelist", $cmctrfdb, 0);
|
|
|
|
$filenamelist->setQuery("SELECT * FROM tdfileattached WHERE tdfileattached.iddata_td='$idtd'");
|
|
$filenamelist->execute();
|
|
while (!$filenamelist->atEnd()) {
|
|
$wa_startindex = $filenamelist->Index;
|
|
?>
|
|
<tr>
|
|
<td>
|
|
<a href="uploadtddocuments/<?php echo ($filenamelist->getColumnVal("filename_fileattached")); ?>" target="_blank"><?php echo $filesent; ?></a>
|
|
</td>
|
|
<td>
|
|
|
|
<?php echo ($filenamelist->getColumnVal("description_fileattached")); ?>
|
|
</td>
|
|
<td>
|
|
|
|
<a href="deletetdaddedoc.php?idtd=<?php echo $idtd; ?>&idtrftd=<?php echo $idtrftd; ?>&idtdadddoc=<?php echo ($filenamelist->getColumnVal("idtdfileattached")); ?>"><i class="fas fa-trash-alt text-danger font-16"></i></a>
|
|
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
$filenamelist->moveNext();
|
|
}
|
|
}
|
|
?>
|