I have created a small helpdesk system which allows users to uploads files when creating tickets. The tickets are stored in a folder with an ID number that matches the ticket details that are stored in a database. Now when I open the ticket details I also want it to list the files associated with that ticket so I can open them. So far I can retrieve all the ticket details but I'm stuck with the json_encode($files) and how I can reference them with my current JavaScript code. Any ideas?
I also have the issue with the . and .. in the scandir() array and would like to remove them. When using the commented line you can see in my PHP file it makes the json_encode array look incorrect. Thanks
PHP file (snippet)
$value = $_POST['value'];
$sql = "SELECT * FROM helpdesk WHERE ID = '$value'";
$result = mysqli_query( $conn, $sql);
while( $rowEdit = mysqli_fetch_array($result))
{
echo json_encode(array($rowEdit['ID'], $rowEdit['DateCreated'], $rowEdit['Name'], $rowEdit['Company'], $rowEdit['Phone'], $rowEdit['Email']));
}
$dir = 'uploads/' . $value .'/';
$files = scandir($dir);
//$files = array_diff(scandir($dir), array('.', '..'));
echo json_encode($files);
HTML file (JavaScript snippet)
$(function(){
/* Opens selected ticket details */
var modal = document.getElementById('modal');
var output = "";
$('#btnEdit').click(function(e){
var value = $("#tblTickets tr.selected td:first").html();
$.ajax({
type : "POST",
url : "sql_helpdesk_ticket_details.php",
data : {value:value},
success : function(output) {
var result = $.parseJSON(output);
$(".modal-body #txtID").val(result[0]);
$(".modal-body #txtDateCreated").val(result[1]);
$(".modal-body #txtName").val(result[2]);
$(".modal-body #txtCompany").val(result[3]);
$(".modal-body #txtPhone").val(result[4]);
$(".modal-body #txtEmail").val(result[5]);
modal.style.display = 'block';
}
});
});