JezK
Edit File: document.php
<?php include("header.php"); if(isset($_POST['action']) && $_POST['action']=='uploadDoc') { // echo "ejbslgkbdfjk";exit; $errors =""; if(isset($_FILES['document']['name']) && $_FILES['document']['name']!=''){ $allowed = array('doc','pdf' ,'docx'); $ext = pathinfo($_FILES['document']['name'], PATHINFO_EXTENSION); if(!in_array(strtolower($ext),$allowed)) { $errors.="Invalid file format please upload pdf or docx or doc\\n"; } } if($errors =='') { $uploadDoc = $users->uploadDoc($_FILES); if($uploadDoc == 1) { echo "<script language='javascript'>alert('Successfully document uploaded');window.location='document.php'</script>"; }else if($uploadDoc == -5){ echo "<script language='javascript'>alert('Document upload Failed');document.getElementById('loaderloader').style.display='none';</script>"; }else{ echo "<script language='javascript'>alert('document upload Failed2');document.getElementById('loaderloader').style.display='none';</script>"; } } } $getDoc = $users->getDocuments(); // print_r($getDoc);exit; ?> <section class="section-padding"> <div class="container bg-white p-4 " > <form action="" method="POST" enctype="multipart/form-data" onsubmit="return checkfileupload()"> <div class="row"> <!-- <div class="col-xl-9 col-12 col-sm-4 col-md-3"> </div> --> <div class="col-xl-3 col-12 col-sm-4 col-md-3"> </div> <div class="col-xl-3 col-12 col-sm-4 col-md-3"> <label for="doc" class="btn basic-btn-color w-100 browsePic">Choose Document</label> <input type="file" id="doc" name="document" class="d-none" accept=".doc,.docx,.pdf" > </div> <div class="col-xl-3 col-12 col-sm-4 col-md-3"> <input type="hidden" name="action" id="action" value="uploadDoc"> <button class="btn basic-btn-color w-100 browsePic">Upload</button> </div> </div> </form> <div class="row justify-content-center pt-5"> <?php if($getDoc==0){?> <div class=" text-center"> <img src="img/documents.png"><br> <p class="pt-2">sorry you have no added document.</p> </div> <?php } else{ $i=0; foreach($getDoc as $k=>$v){ $i++; ?> <div class="container pb-3"> <div class="row"> <div class="col-xl-1 col-sm-6 col-md-4"> <p><?php echo $i ?>.</p> </div> <div class="col-xl-8 col-sm-6 col-md-4"> <p class="text-break"><?php echo $v['document']; ?></p> </div> <div class="col-xl-3 col-sm-6 col-md-4 pull-right"> <!-- <p><a href="uploads/<?php echo $v['document']; ?>" target="_blank">view</a></p> --> <!--<a onclick="openInNewTab('uploads/<?php echo $v['document']; ?>');">Something To Click On</a>--> <?php echo '<a target="_blank" href="documentView.php?docfn='.$v['document'].'" style="color:#00c0f0">View Document</a> | <a href="javascript:void(0)" onclick="return deleteDocument('.$v['id'].')" style="color:#00c0f0">Delete</a> '; /* $extension=explode('.',$v['document']); if(strtolower($extension['1'])=="pdf") { //echo '<a href="uploads/'.$v['document'].'">View Document</a>'; }else{ echo '<a href="documentView.php?docfn='.$v['document'].'">View Document</a>'; //echo '<a href="uploads/'.$v['document'].'">View Document</a>'; }*/ ?> </div> </div> <hr> <!-- <div class="row"> <div class="col-xl-2 col-sm-6 col-md-4"> <p>july 5 th</p> </div> <div class="col-xl-8 col-sm-6 col-md-4"> <p>Payment to 896523164</p> </div> <div class="col-xl-2 col-sm-6 col-md-4 pull-right"> <p>$500</p> </div> </div> --> </div> <?php }}?> </div> </div> </section> <?php include("footer.php");?> <script> function deleteDocument(id){ if(id>0){ if(confirm("Are you sure wants to delete?")) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function(){ if (this.readyState == 4 && this.status == 200){ var data=this.responseText; if(data == 1){ alert('Successfully deleted'); window.location='document.php'; } else if(data == -1){ alert('Invalid document details'); return false; } else{ alert('Deletion Failed');return false; } } }; xhttp.open("GET", "ajax.php?action=deleteDocument&did="+id, true); xhttp.send(); } } } function checkfileupload() { document.getElementById('loaderloader').style.display="block"; var fuData = document.getElementById('doc'); var FileUploadPath = fuData.value; if (FileUploadPath == '') { document.getElementById('loaderloader').style.display="none"; alert("Please upload an document"); return false } var Extension = FileUploadPath.substring(FileUploadPath.lastIndexOf('.') + 1).toLowerCase(); if (Extension != "doc" && Extension != "docx" && Extension != "pdf" && FileUploadPath!='') { document.getElementById('loaderloader').style.display="none"; alert("Please upload .doc or .docx or pdf "); return false; } } $(function() { var start = moment().subtract(29, 'days'); var end = moment(); function cb(start, end) { $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY')); } $('#singleDate').daterangepicker({ // format:'MMMM D, YYYY') , locale: { format: 'MMMM D, YYYY' }, dateFormat: 'MMMM D, YYYY', singleDatePicker: true, showDropdowns: true, minYear: 1901, maxYear: parseInt(moment().format('YYYY'),10) }, function(start, end, label) { var years = moment().diff(start, 'years'); $('#singleDate span').html(start.format('MMMM D, YYYY'), end.format('MMMM D, YYYY')); alert(start.format('MMMM D, YYYY')); alert(end.format('MMMM D, YYYY')); }); }); function openInNewTab(url) { var win = window.open(url, '_blank'); win.focus(); } </script>