1

I have a table showing file location along with other informations. for e.g. :

enter image description here

When the user click on the first row i.e. on $_FILES then it should display the contents of FileA.txt. Is it possible to do this using javascript or using Angular js?

I don't want to use

<input type='file' />

as we already know the file location and also it gives dialog box which ask to save the file, I don't want this. Instead I directly want to show file content. But as I said it shows dialog box which I don't want to show hence looking for alternative.

Thanks in advance,

Ramesh

6
  • Not possible in javascript. With ajax it is possible to display the contents of the file on the server Commented Jun 8, 2015 at 10:02
  • you could use php for this Commented Jun 8, 2015 at 10:02
  • jsfiddle.net/mjzAU/2 Commented Jun 8, 2015 at 10:14
  • @DeepKakkar i have already done this. Just want to do the same but without the browse button as i already have the file location Commented Jun 8, 2015 at 10:17
  • use ajax for that. that is why I have deleted my answer Commented Jun 8, 2015 at 10:18

2 Answers 2

1

You can do this using php:

<?php 
   $filepath = "yourpathhere";
   $content = file_get_contents($filepath);
   echo $content;
?>
Sign up to request clarification or add additional context in comments.

1 Comment

I have some .txt files that have news articles saved in them that are formatted with html tags, so I use this to render articles on their respective pages
1

You need to give file location as id of corresponding <tr>. file_class is class of table. and create a div with class text in which file content will be displayed. JQuery Code is:

$(document).ready(function() {
$(".file_class").click(function() {
var file_location = $(this).attr('id');
    $.ajax({
        url : encodeURIComponent(file_location),
        dataType: "text",
        success : function (data) {
            $(".text").html(data);
        }
    });
});
}); 

HTML Code should be like this:

<table class="file_class"><tr id="D:\input.txt"></tr></table>

6 Comments

I have set table tag as <table id="D:\input.txt" class="file_class"> but success function is not hit hence text div is not filled.
I have already tried that but file_location is 'undefined' and 'data' obtained is the content of the html file hence shows the same table
check firebug what request is going and response. check <tr> tag I have given id of <tr> as file location
setting url: "D:\\input.txt" gives 'Invalid argument' error as for details will check firebug as you mentioned
Use encodeURIComponent() once. you have to encode the string. please comment success or unsuccess.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.