2016-03-29 20 views
0

私のsvnからローカルディスク上のドキュメントに保存されているファイルをダウンロードしました。これらのファイルのほとんどはPHPファイルです。私のローカルディスク上にあるドキュメント(それは "txt"ではない)を読み込み、phpを使用するWebサイト上で開くことができます。だから、今のところ、これは私が持っているもので、phpファイルで読む

index.php 

    $(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 = "cs242_final/home/" . $filePath; 

$file = fopen($url, "r"); 
fread($file,filesize($url)); 

echo '<div class="comment">' . $file . '</div>'; 


?> 

基本的にユーザーが開きたいファイルを入力し、ファイルを自分のローカルディスク上に配置されています。ファイルの内容が印刷されていないので、どこが間違っているのか分かりません。また、私はMAMPを使ってlocalhost上で自分のコードを実行しています。私が使用しているIDEはphpstormです。

答えて

0

fread($file,filesize($url));の値には何も割り当てられていません。試してみてください:

$contents = fread($file,filesize($url)); 
echo '<div class="comment">' . $contents . '</div>'; 

また、これは本番環境で使用されている場合は、ファイル名や悪いことのためのユーザ入力が起こる可能性がありますがproperly escapeことを確認してください。

+0

ファイルが空になっています:/ファイルの内容を認識していません。私が持っているファイルは私のローカルディスク上にありますが、違いがありますか? –

+0

実際には私は "リソースID 3"エラー –

+0

を取得していますそれは、MySQLのエラーですあなたの質問とは関係ありません。 – Mike