1

I've downloaded files from my svn that are now stored in a folder on my local disk. The folder name is cs_DATA and within the folder I have another folder which contains all the files (unncessary but I just saved it that way). These files are the code files I have stored in subversion. Most of these files are php files. How can I read in documents (that aren't "txt") which are located on my local disk and open them on a website that uses php. Currently when I load them in, it echoes out as an empty string. This is what I have

index.php

<script>
$(function() {
    $('#getData').click(function(event) {
        event.preventDefault();

        $.ajax({
            type: "GET",
            url: "endPoint.php",
            data : { field2_name : $('#userInput2').val() },
            beforeSend: function(){
            }
            , complete: function(){
            }
            , success: function(html){
                //this will add the new comment to the `comment_part` div
                $("#displayParse").html(html);
                //$('[name=field1_name]').val('');
            }
        });
    });
});

</script>


<form id="comment_form" action="endPoint.php" method="GET">
    Enter the file you would like to view:
    <input type="text" class="text_cmt" name="field2_name" id="userInput2"/>
    <input type="submit" name="submit" value="submit" id = "getData"/>
    <input type='hidden' name='parent_id' id='parent_id' value='0'/>
</form>

<div id="displayParse">
</div>

endPoint.php

<?php

$filePath = $_GET["field2_name"];
$url = "cs_DATA/files/" . $filePath;
$contents = file_get_contents($url);
echo '<div class="comment">', htmlspecialchars($contents),'</div>';

?>

Nothing is printing out so I can only assume that how I'm accessing my local files is incorrect. I've written my code on phpstorm and am running it on a localhost. The files I need to have access are all stored on my computer. Not sure if that affects it in any way.

Oviya Arasu
  • 193
  • 1
  • 12
  • Tried sending response as `"text/plain"` ? – guest271314 Mar 30 '16 at 03:01
  • _"How can I read in documents (that aren't "txt")"_ If expected result is displaying contents of file within `html` could you send response as MIME type `"text/plain"` ? _"Nothing is printing out"_ Is `
    ` element set as `html` of `#displayParse` ? Tried including `error` handler at `$.ajax()` to check if error occurred ?
    – guest271314 Mar 30 '16 at 03:07
  • hmm, I'm not exactly sure how I would send in a response as text/plain. Could you show me what I would need to add in that case? – Oviya Arasu Mar 30 '16 at 03:18
  • See http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – guest271314 Mar 30 '16 at 03:31

0 Answers0