ppeasy/public/uploadphotofile.php

63 lines
2.1 KiB
PHP

<?php
include('include/headscript.php'); ?>
<?php
if (!empty($_FILES['docphotoone'])) {
// File upload configuration
if (isset($_POST["idtrf"])) {
$idtrf = $_POST["idtrf"];
}
if (isset($_POST["filedescription"])) {
$filedescription = $_POST["filedescription"];
} else {
$filedescription = "";
}
$targetDir = "uploaddocuments/";
$allowTypes = array('jpg', 'jpeg', 'png', 'bmp');
$docss_arr = array();
foreach ($_FILES['docphotoone']['name'] as $key => $val) {
$doc_name = $_FILES['docphotoone']['name'][$key];
$tmp_name = $_FILES['docphotoone']['tmp_name'][$key];
$size = $_FILES['docphotoone']['size'][$key];
$type = $_FILES['docphotoone']['type'][$key];
$error = $_FILES['docphotoone']['error'][$key];
// File upload path
$code = time();
$fileName = basename($_FILES['docphotoone']['name'][$key]);
$fileName = $idtrf . '-' . $code . $fileName;
$targetFilePath = $targetDir . $fileName;
// Check whether file type is valid
$fileType = strtolower(pathinfo($targetFilePath, PATHINFO_EXTENSION));
if (in_array($fileType, $allowTypes)) {
// Store images on the server
if (move_uploaded_file($_FILES['docphotoone']['tmp_name'][$key], $targetFilePath)) {
$docs_arr[] = $targetFilePath;
$UpdateQuery = new WA_MySQLi_Query($cmctrfdb);
$UpdateQuery->Action = "update";
$UpdateQuery->Table = "`trf-details`";
$UpdateQuery->bindColumn("photoone", "s", "$fileName", "WA_DEFAULT");
$UpdateQuery->addFilter("idtrfdetails", "=", "i", "" . ($idtrf) . "");
$UpdateQuery->execute();
$UpdateGoTo = "";
if (function_exists("rel2abs")) $UpdateGoTo = $UpdateGoTo ? rel2abs($UpdateGoTo, dirname(__FILE__)) : "";
$UpdateQuery->redirect($UpdateGoTo);
}
}
}
// Generate gallery view of the images
?>
<ul>
<img src="<?php echo $targetFilePath; ?>" alt="" width="200">
<?php ?>
</ul>
<?php
}
?>