This is a continuation from a previous question, found here:
Display files in directory using PHP and jQuery
I am now able to display the files in a modal window as hyperlinks. What I need to do now is, instead of downloading the files, I need to display the file in a new tab.
Here is how displayFiles.php looks:
if(isset($_POST['editpartnercode']))
{
$partnerCode = $_POST['editpartnercode'];
$bookingNum = $_POST['editbooking'];
$dir = "D:/CargoDocsPDFs/". $partnerCode . "/" . $bookingNum;
$ffs = scandir($dir);
$files = array();
foreach($ffs as $ff)
{
if($ff != '.' && $ff != '..')
{
array_push($files, $ff);
}
}
echo json_encode($files);
}
Using all of the above, I can grab the files from the selected directory and send back over to the JavaScript side, which looks like this:
$('#resultsTable').on('click', 'tr > td > a.uploadDocs', function(e)
{
var editpartnercode = $(this).attr('data-editpartnercode');
var editbooking = $(this).attr('data-editbooking');
var directpath = "D:/CargoDocsPDFs/"+editpartnercode+"/"+editbooking+"/";
$.post('process/displayFiles.php', {editpartnercode:editpartnercode,editbooking:editbooking}, function(data)
{
var obj = JSON.parse(data);
$('#allFiles').empty();
var htmlToInsert = obj.map(function (item)
{
return "<li><b><a href='"+directpath+""+item+"' target='_blank'>" + item + "</a></b></li>";
});
$('#allFiles').html(htmlToInsert);
});
});
Using all of the above, I can return the files to the page in a modal window.
But when I click on the link to open the file, I get the following error message:
Not allowed to load local resource: file:///D:/filelocation/editpartnercode/bookingnum/bookingnum.jpg
How do I fix this error?
file://paths as they are heavily restricted by the browser's security for obvious reasons